← script library
Simplify VMware VM Snapshot Management with PowerShell
VMware & vSphereDecember 24, 2024
In this post, we introduce a PowerShell script that allows you to manage snapshots of your VMware virtual machines effortlessly. Managing snapshots is essential for maintaining the performance and recoverability of your VMs, especially during updates or system changes. This script enables you to create, remove, and list snapshots for specified virtual machines, ensuring that your environment stays organized and efficient. Here is the PowerShell script for managing VMware VM snapshots:
powershell
# Load VMware PowerCLI module
Import-Module VMware.PowerCLI
# Connect to the vCenter Server
$vcServer = "your_vcenter_server"
$credential = Get-Credential
Connect-VIServer -Server $vcServer -Credential $credential
# Define the VM name
$vmName = "YourVMName"
# Create a snapshot
New-Snapshot -VM $vmName -Name "Snapshot_$(Get-Date -Format 'yyyyMMddHHmmss')" -Description "Automated snapshot created by PowerShell" -Memory -Quiesce
# List all snapshots of the specified VM
Get-Snapshot -VM $vmName | Select-Object Name, Created, SizeMB
# Optionally, delete old snapshots
$oldSnapshots = Get-Snapshot -VM $vmName | Where-Object { $_.Created -lt (Get-Date).AddDays(-30) }
if ($oldSnapshots) {
Remove-Snapshot -Snapshot $oldSnapshots -Confirm:$false
Write-Host "Old snapshots removed successfully."
}
Write-Host "Snapshot management completed for VM: $vmName."Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in VMware & vSphere
Ready when you are.
Try ServerEngine free for 7 days.