VMware Cloud Community
berkman
Contributor
Contributor

Use PowerCLI to get VM HA protection status

I have been searching for a way to get the HA protection status for VMs using PowerCLI but I haven't been able to find anything. I saw one way to do it with the VMA VM but I would rather use PowerCLI and PowerShell.

Thanks in advance for your help.

Reply
0 Kudos
20 Replies
LucD
Leadership
Leadership

You mean something like this ?

$cluster = Get-Cluster MyCluster 
Write-Host "Default VM restart" $cluster.HARestartPriority

if($cluster.ExtensionData.Configuration.DasVmConfig){   $cluster.ExtensionData.Configuration.DasVmConfig | %{     Write-Host "VM" (Get-View $_.Key).Name "Restart priority" $_.RestartPriority
  } }


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

Reply
0 Kudos
berkman
Contributor
Contributor

LucD, thanks but that's not what I am looking for, that's the HA restart priority. I am looking for the Unprotected/Protected status of HA for my VMs. I have a couple VMs that are Unprotected and I want to get that into a report but I can't seem to find any command to get this status.

Reply
0 Kudos
LucD
Leadership
Leadership

You mean this

vm-protected.png


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

Reply
0 Kudos
berkman
Contributor
Contributor

Yes sir, that would be the information that I am looking for, is there a way to get that through PowerCLI?

Reply
0 Kudos
herseyc
Enthusiast
Enthusiast

Try this:

get-view -ViewType "VirtualMachine" -Filter @{"Summary.Runtime.DasVmProtection.DasProtected" = "true"} | Select Name

It should return the names of all VMs where the vSphere HA Protection status is Protected.

Hope this helps.

Hersey

vExpert 2013/2012 :: VCAP5-DCD/VCAP5-DCA/VCAP4-DCA/VCP5,4/EMCISA :: http://www.vhersey.com/ :: Follow me: http://twitter.com/herseyc
Reply
0 Kudos
LucD
Leadership
Leadership

Try this

Get-Cluster MyCluster | Get-VM | 
where
{$_.ExtensionData.Runtime.DasVmProtection.DasProtected} |
Select
Name,@{N="Protected";E={$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}

The Where-clause is there to filter out the VMs that are powered off.

If you only want the ones that are not proctected, then you could add an extra condition to the Where-clause


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

nsusa
Contributor
Contributor

This is funny, but I just come here to post a simlar message, looking on how to do this too.

Because I'd like to get a report via email that will show if any VMs are not currently protected in my environment.

I'll try this two commands and see how they work for me.

Thanks,

-Mike

Reply
0 Kudos
herseyc
Enthusiast
Enthusiast

To show only the VMs that are not protected by HA you can use this:

Get-VM | where {$_.ExtensionData.Runtime.DasVmProtection.DasProtected -ne "true"} | select Name

Hersey
vExpert 2013/2012 :: VCAP5-DCD/VCAP5-DCA/VCAP4-DCA/VCP5,4/EMCISA :: http://www.vhersey.com/ :: Follow me: http://twitter.com/herseyc
Reply
0 Kudos
nsusa
Contributor
Contributor

Hi berkman

Did you get the first PS to work for you, I did not, but the second one did, it reported back the protected status as True.

So Guys my thoguhts are will this work as I think, or will we need to cross check that all of our VMs are listed here.

So if a VM is unprotected, the where clause will not work to only find VMs that are currently not protected.

Maybe we should change it to Unprotected machines, currently I do not have any VMs unprotected so its hard to test, does anyone know how I can unprotected a selected VM for testing.

Thanks,

-Mike

Reply
0 Kudos
herseyc
Enthusiast
Enthusiast

Thought you could do this by disabling the VM Restart Priority under Virtual Machine Options is cluster settings but when I do this the VM still shows protected???

It should not display protected if restart priority has been set to disabled but it does.

protected.png

Hersey

vExpert 2013/2012 :: VCAP5-DCD/VCAP5-DCA/VCAP4-DCA/VCP5,4/EMCISA :: http://www.vhersey.com/ :: Follow me: http://twitter.com/herseyc
Reply
0 Kudos
LucD
Leadership
Leadership

If you power on a poweroff VM, it will show Protected equals $false for a couple of seconds.

The VMs that are powered off do not have the property, hence the condition in my Where-clause.

For the ones that are powered on, you will get $true or $false.

If you only want the VMs that are not protected, it suffices to add an extra condition in the Where-clause.

Get-Cluster MyCluster | Get-VM | 
where {$_.ExtensionData.Runtime.DasVmProtection.DasProtected -and !$_.ExtensionData.Runtime.DasVmProtection.DasProtected} | 
Select Name,@{N="Protected";E={$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}


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

Reply
0 Kudos
nsusa
Contributor
Contributor

Thanks LucD, nice work, that will do it.

Take Care,

-Mike

Reply
0 Kudos
berkman
Contributor
Contributor

That didn't work for me but it got me close enough to get this:

Get-Cluster "MyCluster" |

Get-VM |

where {$_.ExtensionData.Runtime.DasVmProtection.DasProtected -ne "True"} |

Select Name,@{N="Protected";E={$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}

Thanks LucD and everyone else.

Reply
0 Kudos
Ranger_rkm
Contributor
Contributor

Berkman,

So did it report back correclty, because I do not have any VMs that are not unprotected, so I would like to know, that if I did it would show them to me.

Also, what report are you adding them to, like to daily emailed report.

Thanks,

-Mike

Reply
0 Kudos
berkman
Contributor
Contributor

Yes, it reported back correctly but also included powered off VMs because the DasProtected value doesn't exist for powered off VMs so I added a where filter:

Get-Cluster "MyCluster" |

Get-VM |

where {$_.PowerState -ne "PoweredOff"} |

where {$_.ExtensionData.Runtime.DasVmProtection.DasProtected -ne "True"} |

Select Name,@{N="Protected";E={$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}

Yes, I am inlcuding this in my daily report email.

Reply
0 Kudos
herseyc
Enthusiast
Enthusiast

How did you test?  Are you able to get a VM to report Unprotected? If so, what did you do?

Thanks

Hersey

vExpert 2013/2012 :: VCAP5-DCD/VCAP5-DCA/VCAP4-DCA/VCP5,4/EMCISA :: http://www.vhersey.com/ :: Follow me: http://twitter.com/herseyc
Reply
0 Kudos
berkman
Contributor
Contributor

I have been able to test successfully because I have a couple VMs that are currently Unprotected. That's why I started to try to get this info into my daily report.

I moved these VMs from one cluster to another and this caused the HA status to go Unprotected. Try that, it should work to get a VM Unprotected.

Reply
0 Kudos
herseyc
Enthusiast
Enthusiast

I guess the point is if the VM does not meet the requirements to be protected, what is the point of reporting on it?

VM with restart priority set to disabled is unprotected yet it reports protected.  Script does not really provide valid/useful results.

Hersey

vExpert 2013/2012 :: VCAP5-DCD/VCAP5-DCA/VCAP4-DCA/VCP5,4/EMCISA :: http://www.vhersey.com/ :: Follow me: http://twitter.com/herseyc
Reply
0 Kudos
Ranger_rkm
Contributor
Contributor

Hi LucD,

If I wanted to have it only show not show powered On VMs, how would l modify the -and! line

$Report = Get-Cluster MyCluster | Get-VM | Sort-Object |
where {$_.ExtensionData.Runtime.DasVmProtection.DasProtected -ne "True"} |
Select Name,@{N="Protected";E={$_.ExtensionData.Runtime.DasVmProtection.DasProtected}} -and !

where{$_.powerstate -eq "PoweredOn"} | Out-String

Here is the output now:

Name                                    Protected                            

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

Test1                                                                       

Test2                                                                       

Both of these VMs are turned off, so I do not want it to show these, also if I update the script, and no VMs are false, will the script fail, because of a null value?

Thanks,

-Mike

Reply
0 Kudos