Finding orphaned, disconnected, inaccessible, invalid vms using PowerCLI.

by Grzegorz Kulikowski

Today i want to show a way of finding vms that are orphaned, disconnected, inaccessible, invalid vms using PowerCLI.
Again , we will be utilizing get-view for that with proper filter.
If the VM gets into status of disconnected, orphaned, inaccessible or invalid it will change it’s connectionstate property. So , basics:
how can we know what kind of connectionstate are thee ?
[sourcecode language=”powershell”]
This property is described on vsphere documentation website -> one one one.
Let’s find now the vms with oprhaned connectionstate.

[sourcecode language=”powershell”]
get-view -ViewType VirtualMachine -Filter @{‘RunTime.ConnectionState’=’orphaned’}


So if you want to look for disconnected instead of orphaned vms, you just change the property ‘connectionstate’ value to ‘disconnected’, or you can just look for other than connected.
[sourcecode language=”powershell”]
get-view -ViewType VirtualMachine -Filter @{‘RunTime.ConnectionState’=’disconnected|inaccessible|invalid|orphaned’} | select name

or the other way around which is , those which are not in the ‘connected’ state:

[sourcecode language=”powershell”]
get-view -ViewType VirtualMachine -Filter @{‘RunTime.ConnectionState’=’^(?!connected).*$’}


You may also like

Leave a Reply

Chinese (Simplified)DutchEnglishFrenchGermanHindiPolishRussianSpanish