elconas
Contributor
Contributor

PowerCLI HARestartPriority not defined for VM

Hello, 
I try to read the "HARestartPriority" of some virtual machines via PowerCLI. However when I query the machine via Get-VM, the property is empty. 
Skript:
PowerCLI> $rc = Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$False -Scope Session
PowerCLI> Connect-VIServer -User "myUser" -Password "myPassword" vcenter
PowerCLI> $clusterObj = Get-Cluster -name "myCluster"
PowerCLI> $clusterObj.HARestartPriority 
Medium
PowerCLI> $vm = Get-VM -Location $clusterObj -Name "myVM"
PowerCLI> $vm.id
VirtualMachine-vm-1035
PowerCLI> $vm.HARestartPriority #<-- This is empty
PowerCLI> 
Whats wrong here (vCenter 5.1) ? 
-------------------------------
PowerCLI Version
----------------
VMware vSphere PowerCLI 5.5 Release 1 build 1295336
---------------
Snapin Versions
---------------
VMWare AutoDeploy PowerCLI Component 5.5 build 1262826
VMWare ImageBuilder PowerCLI Component 5.5 build 1262826
VMware vCloud Director PowerCLI Component 5.5 build 1295337
VMware License PowerCLI Component 5.5 build 1265954
VMware VDS PowerCLI Component 5.5 build 1295334
VMware vSphere PowerCLI Component 5.5 build 1295334
P.s. Sorry for the double posting in vSphere Cli Forum, but that was a mistake 🙂
0 Kudos
7 Replies
LucD
Leadership
Leadership

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

0 Kudos
elconas
Contributor
Contributor

Hi,

actually I have a VM which shows up in vCenter as "High" (it overwrites the HARestartPriority Setting).

VMWare Bug1.png

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>

0 Kudos
LucD
Leadership
Leadership

Does it show up correctly via the script above ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
elconas
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

Then it looks like a "feature" :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
elconas
Contributor
Contributor

Ok, thanks to your skript I now query ExtensionData.Configuration.DasVmConfig and help myself by a lookup hash Smiley Happy

Thanks.

P.s. PowerCLI is great, altought beeing a unix guy I really like the PowerShell interface. Thanks VMWare !

0 Kudos
elconas
Contributor
Contributor



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

0 Kudos