Hello, we have a 5.1 VMware system and I recently set up two scheduled tasks for a particular VM. The first one will use the CLI command of remove-snapshot.
get-snapshot -name * -vm xxxxx | remove-snapshot -RemoveChildren -RunAsync -confirm:$false
This command works ok and does remove the snapshot for server xxxxx,
The next command creates a new snapshot.
get-vm xxxxx | new-snapshot -name Nightly_Snapshot -Description "Created $(Get-Date)" -Memory -Quiesce –RunAsync
This command also works and the new snapshot is created. The commands run about 45 minutes apart which leave plenty of time for the old snapshot to be removed before the new one is created.
These commands are run on a nightly basis. The problem is that now I come in any morning and it asks me to consolidate the disk. When these tasks were done manually through the VSphere client it never asked me to consolidate.
Is there something I have to change in my command so I don't have to consolidate every day?
Thanks for any help.
You could try adding this to your command:
$_.ExtensionData.ConsolidateVMDisks()
So that it looks like this:
get-vm xxxxx | new-snapshot -name Nightly_Snapshot -Description "Created $(Get-Date)" -Memory -Quiesce –RunAsync | $_.ExtensionData.ConsolidateVMDisks()
Source: http://rvdnieuwendijk.com/2012/09/26/use-powercli-to-consolidate-snapshots-in-vsphere-5/
That is great. Since I am pretty new to scripting, the pipe command basically will take the output of the commands before it and pipe it to the consolidate command. This means that consolidate would only run on the one VM in my case with the name of xxxxx correct?
Thanks
Yes, correct. I'm not sure if it will work, because I wasn't able to reproduce your situation quickly (consolidation needed). But that should do the trick, in theory.