Intellectual VMware snapshots


Today we will automate VMware VM snapshots with a New-SmartSnapshot function from my PowerCLi Vi-Module module. The function will utilize the embedded PowerCLi New-Snapshot cmdlet but with some smart features.

New-SmartSnapshot – the smart features

A snapshot name and description

  • The function generates the snapshot name from -Requestor parameter and the current date. By default, the requestor is you ($env:USERNAME variable). This is user account, used to open the PowerShell console.

  • The snapshot description is constructed from account name, used to connect to VCenter plus optional -Description parameter.

  • All you need is to pass VM object(s) to the New-SmartSnapshot function in the pipeline.
Get-VM vm1 | New-SmartSnapshot
  • Note the Snapshot (snapshot name) and Description properties of the returned object.


Multiple snapshots

By default, the New-SmartSnapshot prohibits multiple snapshots for a single VM, but it can be simply changed by using -Force parameter.

Get-VM vm1 | New-SmartSnapshot -Description Patch1
Get-VM vm1 | New-SmartSnapshot -Description Patch2 -Verbose
Get-VM vm1 | New-SmartSnapshot -Description Patch2 -Force


  • If you want to prohibit taking snapshots at all or set maximum allowed snapshot number for any VM(s), please use my Set-MaxSnapshotNumber function.

Multiple VC support

  • Let’s remove all snapshots for our VM and connect to a second VC.
Get-VM lab1vm1 | Get-Snapshot | Format-Table -AutoSize
Get-VM lab1vm1 | Get-Snapshot | Remove-Snapshot –RunAsync
Get-VM lab1vm1 | Get-Snapshot | Format-Table –AutoSize


Connect-VIServer VC2 -wa SilentlyContinue
  • The Set-PowerCLiTitle function is from the Vi-Module too.

  • The Uid property of any VMware object will give us the server through which we are managing that object in the current session.

Get-VM vm1, vm2 | select Name, Uid


  • Here we see that every of these two VM is managed by different VCenter. The New-SmartSnapshot also noticed this and have generated the Description according to this.

Eject VM CD-ROM drive

  • By default the New-SmartSnapshot ejects VM CD-ROM before taking a snapshot, this behavior can be controlled by using -EjectCDDrive parameter. An ISO image, mounted to VM CD Drive as part of VM snapshot will prevent you from deleting the ISO or Datastore itself in the future. This kind of lock is very hard to determine.
Get-VM vm1, vm2 | New-SmartSnapshot -EjectCDDrive:$false

Snapshot progress

  • Taking snapshot procedure runs as a task and visualized by the Write-Progress.


Snapshot VM memory

  • One of cool features of the snapshot technology is ability to save VM memory as part of the snapshot. But if you will try to snapshot powered on VM which has independent disks, the snapshot will fail Emoj. To fix it you will have to manually exclude VM memory from the snapshot.

  • All this dirty work the New-SmartSnapshot will do for you. Instead of fail you will get snapshot with no VM memory.

Snapshot report

  • The New-SmartSnapshot can work in read only mode with -ReportOnly parameter. Retrieve existing snapshots and do nothing.

Get-VM | New-SmartSnapshot -ReportOnly
Get-VM vm1, vm2 | snap -ReportOnly | ft –au



  • For more details about the function, please take a look at the content based help and examples.
Get-Alias –Definition New-SmartSnapshot
Get-Help New-SmartSnapshot -Full
Get-Help New-SmartSnapshot -Examples
Get-Help New-SmartSnapshot -Parameter EjectCDDrive

You might also like

Set-PowerCLiTitle – Connect-VIServer deep dive
Set-MaxSnapshotNumber – Control maximum number of VMware snapshots
Copy VMware VM Notes to Computer/AD Computer Description
Expand-VMGuestPartition – Extend VM Guest Partition w/PowerCLi

4 thoughts on “Intellectual VMware snapshots

  1. is there a way to remove the CD ISO from a Snapshot that is already made without rolling back the VM? We made snapshots where the ISO was mounted in the past.


    1. 1. Allow and open SSH to any ESXi host that has access to the VM Datastore.

      2. Find VM snapshots, these are *.vmsn files in the VM folder.

      ls /vmfs/volumes/Datastore/Folder/*.vmsn

      3. Open your snapshot file.

      vi /vmfs/volumes/Datastore/Folder/VM-Snapshot1.vmsn

      4. Locate lines, starting with ide, the ide1:0.filename will contain path to the ISO file.

      ide1:0.deviceType = "cdrom-image"
      ide1:0.fileName = "/vmfs/volumes/DatastoreGuid/Folder/Isofile.iso"

      5. Replace ide1:0.deviceType and ide1:0.fileName parameters by following values.

      ide1:0.deviceType = "cdrom-raw"
      ide1:0.fileName = "emptyBackingString"

      6. Exit from the vi editor and save the changes :w.

      PS. I don’t think this is supported by VMware 🙂
      Backup your vmsn files before editing…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s