Sunday, March 25, 2012

Creating a new snapshot for virtual machines in a folder with VMware vSphere PowerCLI

One of the tasks I find myself doing quite a bit is creating new snapshots for a bunch of virtual machines a in a folder after a routine patch window and while using the vSphere Client doesn’t take too long for 5 to 10 templates, I would still prefer to execute a line in vSphere’s PowerCLI to automate the process so the following serves to demonstrate this and also provide me with something to reference to in the future.

In order to use the following cmdlet, you’ll need to make sure all of the virtual machines you want to create a snapshot is in filed into a folder:

image

As shown in the screenshot above, the folder containing the virtual machines I would like to create a snapshot is the Master Images folder.  Once you have the name of the folder containing the virtual machines you want to create a snapshot for, proceed with deciding on what you want to name the snapshot as.  For the purpose of this example, I’ll use the name March 25 Test as the snapshot name which will have the cmdlet look as follows:

Get-VM -Location "Master Images" | New-Snapshot -Name "March 25 Test" -Confirm:$false

image

Executing the command won’t really output any results but once it completes, you should see the see something similar as the screenshot above.

No comments: