VMware Cloud Community
rtemplejr
Contributor
Contributor

using shutdown-vmguest w/o having to confirm

This weekend we have a planned power outage and I would like to group my system into folders or a list so i can use powershell to shutdown the systems in a specific order.

Is there and easy way to script a tiered shutdown without having to confirm each vm when executed. I've tried using get-content and get-folder but all scenarios lead tme to selecting yes for all of the vm's.

0 Kudos
4 Replies
LucD
Leadership
Leadership

Use the Confirm parameter

Get-VM | Shutdown-VMGuest -Confirm:$false

And if you have the names in a text file, you can do

Get-VM  -Name (Get-Content "C:\vmnames.txt") | Shutdown-VMGuest -Confirm:$false


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

0 Kudos
rtemplejr
Contributor
Contributor

Thank you.  I was able to get the following string to work:

get-content c:\powershell\tier4.txt | % {get-vm $_ | shutdown-vmguest –confirm:$false}

Is there a way to easilt add sleep-time or $waittime between the shutdowns?

0 Kudos
LucD
Leadership
Leadership

Sure, try it like this

get-content c:\powershell\tier4.txt | % {

   get-vm $_ | shutdown-vmguest –confirm:$false

   sleep 5

}

The script will pause 5 seconds after each shutdown command


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

0 Kudos
rtemplejr
Contributor
Contributor

Perfect. Thank you!

0 Kudos