Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Create List or Remove VMware VM Snapshots with PowerCLi

This is very handy and useful Powercli script, when I do my labs or production deployment changes on VMware environment. Whenever I have multiple servers to make changes and wants to ensure no problem should occur after changes, I take temporary VMware snapshots. But working with snapshot manually in GUI on multiple VMs, it is time consuming and sometimes there is no accuracy. Here to have perfection while creating snapshots I use VMware PowerCLI and automate the task, it saves lots of time with accuracy.

In below script I have lists of VMs and snapshot name. First command is Get-VM and using same information create new snapshot with command New-Snapshot using parameters.



$date = Get-Date 
$vmList = ('k8smaster01', 'k8smaster02', 'k8smaster03','k8sworker01','k8sworker02','k8sworker03')
$snapshotName = 'Fresh Deploy'

$vms = Get-VM -Name $vmList
$vms | New-Snapshot -Name $snapshotName -Description $date.DateTime -Memory:$true -Confirm:$false

I can verify snapshot is created on one of the VM on vCenter UI.

In the last if you want to get the list of snapshots, you can use Get-Snapshot and to delete snapshot use Remove-Snapshot command as shown below.

$vms | Get-Snapshot
$vms | Get-Snapshot | Remove-Snapshot -RemoveChildren -Confirm:$false

Useful Articles
Resolved syslog error: Call OptionManager.UpdateValues for object ha-adv-options on ESXi failed
Solved: Esxi server cannot joined into active directory domain
Solved Esxi host disconnected evaluation license expired
Connect-VIServer Error: Invalid server certificate. Use Set-PowerCLIConfiguration
VMware PowerCLI Connect-VIserver Could not connect using the requested protocol
VMware PowerCLI The remote server returned an error: (407) Proxy Authentication Required
VMware PowerCLI Connect-VIServer Object reference not set to an instance of an object
VMware PowerCLI esxcli namespace command elements empty no output



This post first appeared on Tales From Real IT System Administrators World And Non-production Environment, please read the originial post: here

Share the post

Create List or Remove VMware VM Snapshots with PowerCLi

×

Subscribe to Tales From Real It System Administrators World And Non-production Environment

Get updates delivered right to your inbox!

Thank you for your subscription

×