VMware Cloud Community
smccreadie
Enthusiast
Enthusiast
Jump to solution

Start-VM fails on a disconnected VM in vsphere

Hello,

I have a question regarding the Start-VM cmdlet in vsphere. I am trying to use it to power on a bunch of VM's in my disaster recovery site, as well as answer a VM question that comes up frequently. It works well until it encounters a VM that is registered in inventory but is disconnected for some reason. (Generally its because the storage the VM is located on is no longer present) I dont want to remove these VM's from inventory, but i just want the Start-VM process to skip that VM. I need to loop through all the VM's and discover the property that shows the conenction state of the VM. Does anyone know how to do this? Any help is most appreciated. Thanks

Sean

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could use a Where-Object to filter out guests that are on datastores that are not connected.

Something like this

Get-Vm | Where {($_ | Get-Datastore).Accessible} | Start-Vm


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

You could use a Where-Object to filter out guests that are on datastores that are not connected.

Something like this

Get-Vm | Where {($_ | Get-Datastore).Accessible} | Start-Vm


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

Reply
0 Kudos
smccreadie
Enthusiast
Enthusiast
Jump to solution

LucD,

Thank you for the response. So I tried that and unfortunately the datastores return values for get-datsatore, even though they are inaccessible in the VIC. So is there anyway to have the Start-VM cmdlet run through each object and ignore the failure? When i run Start-VM it throws and error visible in the VIC like this "unable to comminicate with the remote host, since it is disconnected", and hte script just hangs and wont continue to the next VM. Thanks again for all the help, ill keep digging.

Sean

Reply
0 Kudos
smccreadie
Enthusiast
Enthusiast
Jump to solution

LucD,

Nevermind. You were right initially of course. I tried it again and discovered that it is working! So im gonna tweak it a little and see if I can get it just right, but I think this is just the code I needed to do what I needed. Thanks again.

Sean

Reply
0 Kudos