VMware Cloud Community
bmeche
Contributor
Contributor
Jump to solution

Script to Power On VMs That Are Off

I'm looking for a quick PowerCLI script that will power on any VMs that are powered off in a folder. I plan on setting a task to run daily at a certain time for a VDI folder where end users sometimes shut down machines. The script should ignore any VM that's powered on, but power on and VM that's off.

I'm not a scripting genius, so I was hoping someone had a similar script sitting around. Using Google and looking over this forum, the scripts seemed to be more for powering off and on VMs using a CSV / .TXT, but I'm just hoping for something that powers on any VMs that are powered off without needing to create or maintain a text file.

Thanks in advance

0 Kudos
1 Solution

Accepted Solutions
JuJik
Contributor
Contributor
Jump to solution

here is a very simple few liner:

#get all powered off VMs

$powered_off_VMs = get-vm * | where {$_.powerstate -like "*off*"}

#Execute start-vm for each powered off VM

foreach ($vm in $powered_off_VMs)

{

Start-VM -VM $vm.name -Confirm:$false -RunAsync

}

if you need a more complex script, have a look at Alan's old post: http://www.virtu-al.net/2011/12/14/vm-start-up-script/

View solution in original post

0 Kudos
3 Replies
JuJik
Contributor
Contributor
Jump to solution

here is a very simple few liner:

#get all powered off VMs

$powered_off_VMs = get-vm * | where {$_.powerstate -like "*off*"}

#Execute start-vm for each powered off VM

foreach ($vm in $powered_off_VMs)

{

Start-VM -VM $vm.name -Confirm:$false -RunAsync

}

if you need a more complex script, have a look at Alan's old post: http://www.virtu-al.net/2011/12/14/vm-start-up-script/

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM | where{$_.PowerState -eq 'PoweredOff}' | Start-VM -Confirm:$false


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

0 Kudos
bmeche
Contributor
Contributor
Jump to solution

Worked great with a few simple modifications. Thanks for getting me on the right track!

0 Kudos