VMware Cloud Community
svmware23
Contributor
Contributor

Shutdown vms on datastore

Need a ps script to shutdown all vm's on specific datastore and to exclude some of the vm's. thank you in advance.

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

What do you already have?


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

Reply
0 Kudos
svmware23
Contributor
Contributor

thank you for quick reply LuCD, here it is- 

this is the script i have to shutdown all vms except in *, but would like to add cluster and datastore specific 

Get-VM | Where-object {$_.name -notlike '*******' } | Stop-VMGuest -Confirm:$false

newbie to PowerShell , appreciate your help and thank you in advance.

Reply
0 Kudos
LucD
Leadership
Leadership

You can use the Datastore parameter to limit the returned VMs to only the ones on that datastore

Get-VM -Datastore MyDS | 
Where-object {$_.name -notlike '*******' } | 
Stop-VMGuest -Confirm:$false


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

Reply
0 Kudos
svmware23
Contributor
Contributor

how about cluster filtering?

Reply
0 Kudos
LucD
Leadership
Leadership

Use the Location parameter on the Get-VM cmdlet.


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

Reply
0 Kudos
svmware23
Contributor
Contributor

can share the command so i can try on.

Reply
0 Kudos
LucD
Leadership
Leadership

Which command?
It is the same command, just add the Location parameter.


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

Reply
0 Kudos