I have a couple scripts to create and remove snapshots for a group of servers. When I remove the snapshots it does it one at a time, but when I create the snapshots it tries to do them all at once which tends to overload the hosts. Does anyone know of an option that I am missing to have it create the snapshots one at a time?
Here is what I use to create the snapshots
get-vm -location “Test-Env” | New-Snapshot -Memory -Quiesce -Name Snap1
Here is what I am using to remove the snapshots
get-vm -location “Test-Env” | Get-Snapshot -Name Snap1 | Remove-Snapshot
The problem is you use location which is a collection (probably resource pool), so it tries to do them all in one go.
The New-Snapshot command should run each one and wait it you refer to it per VM. Using RunAsync command stops it waiting for each one, default is off.
https://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/New-Snapshot.html
So you don't need to sleep
$VMS = get-vm -location “Test-Env”
foreach ($VM in $VMS)
{
$Snapshot = $VM | New-Snapshot -Memory -Quiesce -Name Snap1
}