Tools are already confirmed present/running on the target VMs. We're potentially running the shutdown script (and then power on script) against 88 VMs. I'm pretty sure we'll execute the smaller count VM groups manually while running the scripts as concurrently as possible (by the people doing this).
The VMs NEED to power off in a set order. They also NEED to power on in the reverse of that order due to what's running on them and how they interact. Such as having a database VM power off after the previous VMs are down. Then powering up, and making sure SQL is running before the rest are powered up. I suppose the power on set isn't AS critical, since a maintenance reboot will be taking place as part of the entire process.
We have less than 300 VMs total to manage on this. With the task taking place on Tuesday (April 7), I need to get the scripts themselves finished before too far into Monday. We're going to be tight on time for both the shutdown and power on tasks as it sits. Adding more time to the function with a 'tools check' item is suboptimal. Maybe if we ran that part the day before, but we can get the exact same effect by simply adding the Tools item(s) the the Inventory field display. There are times when scripting, or ADDING to a script just isn't of benefit.
I'm more interested in the actual working aspects of the scripts to ensure those parts work as intended. IMO, trying to go through all ~300 VMs manually to do the Shutdown/power on is insanity.
I'm already planning to perform some tests with the script for both shutdown and power on. I was kind of hoping that @LucD would see this thread and grace it with his wisdom. 😅
I did just find out that the actual power on timing isn't as important. The order might not even be that important. Which is good to find out.
Original Message:
Sent: Apr 03, 2026 08:50 AM
From: snapfriend
Subject: Need a script to POWER ON VMs from feeder file with pause
Hello @AGold
Your script is having some actual scenario missing.
When you do "Shut Down" guest OS from vCenter then VMware Tools perform an action to shutting down the Guest OS. So, you need to check if every machines are having VMware Tools running & installed (Check 1).
When you do "Shut Down" guest OS then sometimes, Windows OS didn't shutdown correctly & holds or wait for longer time to shutdown the VM. You have check where you are waiting for complete VM powered off event. It will miss & your next VM will not be performed unless complete power off is complete (Check 2)
When you do "Shut Down" guest OS then sometimes, Windows OS is having pending patches which are normally got stuck to complete shutdown of the VM unless 100% patches got completed (Check 3)
As per above 3 checks, you need some manual intervention when there is long pending task remaining & not proceeding further. So, 80% success ratio & 20% failure ratio as per my experience.
Now, we will move to Power ON
When you start the VM then VM immediately gets powered on & there is no need to wait for 10 sec. or sleep 10 sec. VM's state become powered on very quickly without any hassle. Sometimes, VMs not getting powered on due to certain reasons & you will come to know when you faced the issue. So, 95% success ratio & 5% failure ratio as per script logic as per my experience.
Kindly test the script on test machines with required VMs added into "poweronlist.txt". All the best for your activity.
Original Message:
Sent: Apr 02, 2026 03:40 PM
From: AGold
Subject: Need a script to POWER ON VMs from feeder file with pause
We're shutting down the environment next week for some maintenance work (can't be avoided). I have a couple of scripts that we'll be using to power off the VMs at this point. One script is for VMs that need to be powered off in a set order, with a wait until the previous VM is actually off before proceeding. The other is for the rest of the VMs to just get the Shutdown-Guest command all at once. Obviously, I'm using the graceful shutdown command for both sets.
What I'm looking for is another script, or how to alter the ordered script, to power ON the listed VMs with a wait between them so that they don't come up too fast. This is my shutdown script:
# Connect to vCenter
Connect-VIServer -Server <vcenterservername>
# List of VMs to shut down
foreach ($vm in Get-Content .\powerofftest1.txt)
foreach ($vmName in $vmNames) {
$vm = Get-VM -Name $vm
if ($vm.PowerState -eq 'PoweredOn') {
Write-Host "Initiating shutdown for $vmName..."
Shutdown-VMGuest -VM $vm -Confirm:$false
# Wait for the VM to actually power off
do {
Start-Sleep -Seconds 10
$vm = Get-VM -Name $vmName
Write-Host "Waiting for $vmName to power off..."
} until ($vm.PowerState -eq 'PoweredOff')
Write-Host "$vmName is powered off."
}
}
# Disconnect
Disconnect-VIServer -Confirm:$false
I'm 99% sure this will work as intended. Can anyone advise what I should alter in the following to basically do the same thing for the power on sequence? Probably my largest question is how to get it to see that the target VM is actually up (into the OS), easily? At present, we have anywhere from two to over twenty VMs in each feeder file. I can see how we'll probably not use the scripting for a low VM count. But when we get to the more complicated boot orders, I think the script could save us pain. The blast of Shutdown-Guest and the Start-VM list is almost 200. If it wasn't for there being VMs that we leave off (for various reasons) I'd probably just use a single command to turn everything on once the VMs that need to be done in order, are up.
Power ON script as it sits right now. Open to suggestions/improvements:
# Connect to vCenter
Connect-VIServer -Server <vcenterservername>
# List of VMs to power on
foreach ($vm in Get-Content .\poweronlist.txt)
foreach ($vmName in $vmNames) {
$vm = Get-VM -Name $vm
if ($vm.PowerState -eq 'PoweredOff') {
Write-Host "Initiating power on for $vmName..."
Start-VM -VM $vm -Confirm:$false
# Wait for the VM to actually power on
do {
Start-Sleep -Seconds 10
$vm = Get-VM -Name $vmName
Write-Host "Waiting for $vmName to power on..."
} until ($vm.PowerState -eq 'PoweredOn')
Write-Host "$vmName is powered on."
}
}
# Disconnect
Disconnect-VIServer -Confirm:$false
-------------------------------------------