Virtual Geek

Tales from real IT system administrators world and non-production environment

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.

$user =  'Administrator@vsphere.local'
$password = 'password'
Connect-VIServer -Server -User $user -Password $password

$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

Microsoft Powershell VMware PowerCLI vcenter esxi snapshots features vmlist get-vm New-Snapshot Memory date description confirm kubernetes lab k8s.png

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

Vmware vCenter vcsa esxi virtualization vmware.powercli powershell module fresh deploy kubernetes master worker k8s take snapshot permissions configure datastores management.png

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

Microsoft Powershell Vmware Powercli get-snapshot remote-snapshot new-snapshot memory poweredon poweredoff vcenter vcsa esxi kubernetes lab free k8s.png

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

Go Back


Blog Search

Page Views


Follow me on Blogarama