Today I’m attending the ITCampNL in Eindhoven where two Microsoft employees are giving a workshop on Hyper-V in Windows Server 2012.
One of the things they asked me on the spot were a few management tasks through PowerShell such as restoring all virtual machines to a snapshot that has previously been taken.
Than I came to think about it and I would like a few PowerShell one liners to do everything with snapshots that is required for a demo and/or training environment such as creating snapshots, reverting to them and even deleting them.
So… here we go.
To create snapshots on all virtual machines:
Get-VM -Name * | Checkpoint-VM -SnapshotName 'ITCamp Baseline'
And to revert all virtual machines to those snapshots:
Get-VM -Name * | Foreach-Object {Restore-VMSnapshot -VMName $_.Name -Name 'ITCamp Baseline'}
Next is of course to remove the snapshots:
Get-VM -Name * | ForEach-Object {Remove-VMSnapshot -VMName $_.Name}
And finally to remove the snapshots and all child snapshots:
Get-VM -Name * | ForEach-Object {Remove-VMSnapshot -IncludeAllChildSnapshots -VMName $_.Name}
I hope that you find these as useful as I’m hoping you will