How to control maximum number of VMware snapshots w/PowerCLi

Cover

Six years ago, the VMware guru William Lam wrote this excellent article. Today we will automate his solution with PowerCLi.

Please meet the Set-MaxSnapshotNumber function from my PowerCLi Vi-Module module.

The function can do three things:

  • Get maximum allowed snapshot number

  • Set maximum allowed snapshot number

  • Prohibit taking snapshots at all

Moreover, it is all for multiple VMs.

Let’s see examples.

  • Get report with –Report parameter.
Get-Cluster PROD | Get-VM | Set-MaxSnapshotNumber -Report

01.Set-MaxSnapshotNumber_Report

  • Prohibit taking snapshots for particular VM(s).
Get-VM vm1, vm2 | Set-MaxSnapshotNumber 0

02.Set-MaxSnapshotNumber_Prohibit Snapshot

After that, we will not be able to take snapshots for this VM and will get error message in the Recent Tasks pane.

03.Set-MaxSnapshotNumber_CreateSnapshotTaskFailed

The same error we will get in the PowerCLi console while trying to take a snapshot.

04.Set-MaxSnapshotNumber_CreateSnapshotPCLiFailed

The function supports –Confirm flag to suppress the confirmation dialog while creating a snapshot. Use it carefully in production environments!

Get-VM vm1, vm2 | Set-MaxSnapshotNumber –Number 5 –Confirm:$false

05.Set-MaxSnapshotNumber_Confirm

The –Number parameter may be any integer from zero to 496.

  • Zero – Snapshots prohibited

  • 496 – Maximum supported value

  • 31 – The default value

This is positional parameter and it can be omitted. It is enough to supply its value only. If you omit the value itself too, the default value 31 will be used.

Get-VM vm1, vm2 | Set-MaxSnapshotNumber 496
Get-VM vm1, vm2 | Set-MaxSnapshotNumber

06.Set-MaxSnapshotNumber_ValidateParam

Very important!

  • The function does not affect existing snapshots (does not delete, does not disable or whatever).

In below example we have VM with 20 existing snapshots and 31 snapshots allowed. We prohibit snapshots for this VM (set maximum allowed snapshot number to zero). After that, we cannot create no one additional snapshot, but all previously created snapshots are in order.

07.Set-MaxSnapshotNumber_ExistingSnapshots

  • The function does not do any manipulations with snapshots themselves. It only edits one specific VM advanced setting, named snapshot.maxSnapshots.

VM -> Edit Settings… -> VM Options tab -> Advanced category -> Edit Configuration… button

  • This setting affects future snapshots only.

08.Set-MaxSnapshotNumber_VMSettings1

09.Set-MaxSnapshotNumber_VMSettings2

For those of you who loves short commands I have added alias for the Set-MaxSnapshotNumber, named maxsnap.

Get-Alias -Definition Set-MaxSnapshotNumber
Get-VM vm1 | maxsnap 2

10.Set-MaxSnapshotNumber_Alias

For more details about the function, please take a look at the content based help and examples.

Get-Help Set-MaxSnapshotNumber –Examples
Get-Help Set-MaxSnapshotNumber –Full
Get-Help Set-MaxSnapshotNumber –Parameter Number

You may also like:

Test-VMHotfix/Test-VMPing – Check VMware VM for installed Hotfixes
Move-Template2Datastore – Migrate VMware VM Templates to another Datastore
Get-RDM – How to get RDM (Raw Device Mappings) disks
Convert-VmdkThin2EZThick – Convert Thin Provision VMDK disks to Thick

3 thoughts on “How to control maximum number of VMware snapshots w/PowerCLi

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s