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
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/
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/
Try like this
Get-VM | where{$_.PowerState -eq 'PoweredOff}' | Start-VM -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Worked great with a few simple modifications. Thanks for getting me on the right track!