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


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 ?

[enum]::GetNames([vmware.vim.virtualmachineconnectionstate])
connected
disconnected
orphaned
inaccessible
invalid

This property is described on vsphere documentation website -> one one one.
Let’s find now the vms with oprhaned connectionstate.

get-view -ViewType VirtualMachine -Filter @{'RunTime.ConnectionState'='orphaned'}

oprhanedvm

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.

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:

get-view -ViewType VirtualMachine -Filter @{'RunTime.ConnectionState'='^(?!connected).*$'}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s