Afaik this is normal.
When your VM restart priority is set to "Use cluster setting", the entry in the VM is in fact blank.
You could do something like this
$cluster = Get-Cluster Myluster
$cluster.ExtensionData.Configuration.DasVmConfig |
Select @{N="VM";E={Get-View $_.Key -Property Name | Select -ExpandProperty Name}},
@{N="RestartPriority";E={if($_.RestartPriority){$_.RestartPriority}else{"Use cluster setting"}}}
That takes care of the blank
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
actually I have a VM which shows up in vCenter as "High" (it overwrites the HARestartPriority Setting).
If I run the same command for this VM, is does also return an empty response, so it may a PowerCLI issue ??
PowerCLI> $vm = Get-VM -Location $clusterObj -Name "SRV-VCENTER01"
PowerCLI> $vm.HARestartPriority # <-- also empty.
PowerCLI>
Does it show up correctly via the script above ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nope, the property "HARestartPriority" is empt:
PowerCLI> if ($vm.HARestartPriority -eq $Null) { Write-Host "Nope, empty" }
Nope, empty
With your Script I get the correct Value:
VM RestartPriority
-- ---------------
SRV-VCENTER01 high
Regards,
Robert
Then it looks like a "feature" :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, thanks to your skript I now query ExtensionData.Configuration.DasVmConfig and help myself by a lookup hash
Thanks.
P.s. PowerCLI is great, altought beeing a unix guy I really like the PowerShell interface. Thanks VMWare !
For the sake of completeness and for everyone having the same issue:
It looks like I found why HaRestartPriority is empty.
If you run Get-VM without -Location, everything is OK:
PowerCLI> Get-VM -Name "srv10051" | Select-Object Name,HARestartPriority
Name HARestartPriority
---- -
srv10051 ClusterRestartPriority
If you run with -Location (beeing the Cluster), the Property is empty:
PowerCLI> $clusterObj = Get-Cluster -name $clustername
PowerCLI> Get-VM -Location $clusterObj -Name "srv10051" | Select-Object Name,HARestartPriority
Name HARestartPriority
---- -
srv10051
I don't know why, but it is like this 🙂
So my workaround is: filter Based on Vm.VMHost.Parent.Name (which contains the cluster name)
PowerCLI> Get-VM | Where-Object {$_.Host.Parent.Name -eq "Dev-Cluster"} | Select Name,HaRestartPriority
Veeeeery old thread, but I just stumpled over the same problem.
I search with the scope of datastores for the HARestartPriority setting:
$vms = $datastore|get-vm|where{$_.name -notmatch "vCLS-"}
foreach ($vm in $vms) ..... and so on
The problem on the whole thing is, that the VM-Objects in the $vms array are of type:
TypeName: VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl
which seem to have this setting always as $null
If you do a get-vm $vm you get the type
TypeName: VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl
So you have to do another get-vm although you already have VM-Object.
So my solution is this:
$vms = $datastore|get-vm|where{$_.name -notmatch "vCLS-"}
foreach ($vm in $vms)
{
$vmobj = get-vm $vm
if ($vmobj.HARestartPriority -ne "High")
{
Set-VM $vm -HARestartPriority "High" -RunAsync:$true -Confirm:$false
}
}
s