VMware vSphere

 View Only
Expand all | Collapse all

Powershell Script to export cluster DRS and HA configurations as csv file

  • 1.  Powershell Script to export cluster DRS and HA configurations as csv file

    Posted May 22, 2024 10:26 AM

    Hi,

    We have dozens of vcenters, I need a common script to use on each to get output of Cluster DRS and HA configurations to save as csv file.

    Can be seperate scripts to run on Powershell by connecting to each vCenter.

    I am not sure where to start.
    I can describe which options need to be listed if this helps the scripting process.



  • 2.  RE: Powershell Script to export cluster DRS and HA configurations as csv file

    Posted May 23, 2024 03:31 AM
    Edited by RaF_Man_723 May 23, 2024 03:31 AM

    hello,

    I hope the command and script below can help you, it's what I use.

    1/ to get drs rules

    ----------

    Get-VM |Select Name,@{N='DRSGroup';E={$script:group = Get-DrsClusterGroup -VM $_; $script:group.Name}},@{N='GroupType';E={$script:group.GroupType}}

    ------------------

    2/ to get Vm not in DRS:

    ----------------------

    foreach ($Cluster in Get-Cluster) {
        Write-Host "`n"
        Write-Host $Cluster.Name
        add-content .\notindrs.txt $Cluster.Name
        $ClusterVMs = ($Cluster | Get-VM)
        $GroupVMs = $null
        foreach ($DrsGroup in ($Cluster | Get-DrsClusterGroup)) {
            $GroupVMs = $GroupVMs + $DrsGroup.Member
        }
        foreach ($VM in $ClusterVMs) {
            if ($VM -notin $GroupVMs) {
            add-content .\notindrs.txt $VM.name 
            Write-Host "`t" $VM.name}
        }
    }

    ---------------------

    3/ to get the DRS List:

    ---------------

    foreach ($Cluster in Get-Cluster) {
        #Write-Host "`n"
        #Write-Host $Cluster.Name
        $ClusterVMs = ($Cluster | Get-VM)
        $GroupVMs = $null
         foreach ($DrsGroup in ($Cluster | Get-DrsClusterGroup)) {
    #Write-Host "`t" $Cluster.Name,",",$DrsGroup,",",$DrsGroup.Member
    #echo "`t" $Cluster.Name,",",$DrsGroup,",",$DrsGroup.Member >> drs.csv
    add-content .\drs.txt $Cluster.Name,$DrsGroup,$DrsGroup.Member
    #$result +=$Cluster.Name,",",$DrsGroup,",",$DrsGroup.Member
    }
         
    }
    Write-Host $result 
    #add-content .\drs.txt $result