I've come up on a bit of an issue where I need to generate an HA compliance report for our clusters which have VM Overrides configured. About half of the given VMs in a cluster have their HA restart priority set to disabled, so they don't need to be included in the report totals. However, those VMs still have the DASProtected property returning, so I'm not sure how to go about filtering these VMs out so I can collect accurate usage totals for VMs that need to be failed over.
This is the script I have so far that returns info for each VM; the data isn't sorted yet.
&{Get-View -ViewType VirtualMachine | %{
New-Object PSObject -Property @{
Name = $_.Name
Host = Get-View $_.Summary.Runtime.Host | Select -ExpandProperty Name
CPU = $_.Config.Hardware.NumCPU
vCPU = &{if($_.Config.Hardware.NumCoresPerSocket -gt 0){$_.Config.Hardware.NumCPU/$_.Config.Hardware.NumCoresPerSocket}}
MemConfiguredMB = $_.Summary.Config.memorySizeMB
DASEnabled = &{if($_.Runtime.dasvmprotection.dasProtected){$_.Runtime.dasvmprotection.dasProtected}else{$false}}
}
}}
To be clear, DASEnabled shows up as true right now for all VMs that are online and running, which doesn't help me.
The VM restart priority is kept in the Cluster object.
You can do something like this
$clusterName = 'MyCluster'
$cluster = Get-View -ViewType ClusterComputeResource -Filter @{'Name'=$clusterName}
$vmDRestartisabled = $cluster.ConfigurationEx.DasVmConfig | where{$_.DasSettings.RestartPriority -eq [VMware.Vim.ClusterDasVmSettingsRestartPriority]::disabled} | %{
Get-View -Id $_.Key -Property Name | select -ExpandProperty Name
}
Get-View -ViewType VirtualMachine | where{$vmDRestartisabled -notcontains $_.Name} | %{
New-Object PSObject -Property @{
Name = $_.Name
Host = Get-View $_.Summary.Runtime.Host | Select -ExpandProperty Name
CPU = $_.Config.Hardware.NumCPU
vCPU = &{if($_.Config.Hardware.NumCoresPerSocket -gt 0){$_.Config.Hardware.NumCPU/$_.Config.Hardware.NumCoresPerSocket}}
MemConfiguredMB = $_.Summary.Config.memorySizeMB
DASEnabled = &{if($_.Runtime.dasvmprotection.dasProtected){$_.Runtime.dasvmprotection.dasProtected}else{$false}}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The VM restart priority is kept in the Cluster object.
You can do something like this
$clusterName = 'MyCluster'
$cluster = Get-View -ViewType ClusterComputeResource -Filter @{'Name'=$clusterName}
$vmDRestartisabled = $cluster.ConfigurationEx.DasVmConfig | where{$_.DasSettings.RestartPriority -eq [VMware.Vim.ClusterDasVmSettingsRestartPriority]::disabled} | %{
Get-View -Id $_.Key -Property Name | select -ExpandProperty Name
}
Get-View -ViewType VirtualMachine | where{$vmDRestartisabled -notcontains $_.Name} | %{
New-Object PSObject -Property @{
Name = $_.Name
Host = Get-View $_.Summary.Runtime.Host | Select -ExpandProperty Name
CPU = $_.Config.Hardware.NumCPU
vCPU = &{if($_.Config.Hardware.NumCoresPerSocket -gt 0){$_.Config.Hardware.NumCPU/$_.Config.Hardware.NumCoresPerSocket}}
MemConfiguredMB = $_.Summary.Config.memorySizeMB
DASEnabled = &{if($_.Runtime.dasvmprotection.dasProtected){$_.Runtime.dasvmprotection.dasProtected}else{$false}}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much for taking the time to share this answer - it works perfectly.