← script library

Automating VM Snapshot Management in vSphere Using PowerShell

VMware & vSphereJanuary 6, 2025

As virtual environments continue to grow, managing snapshots becomes crucial for effective system recovery and resource management. This PowerShell script automates taking new snapshots of virtual machines in a VMware vSphere environment. The script will connect to the vCenter server, grab all VMs, and create a snapshot for each.

powershell
# Define your vCenter server and credentials
$vCenterServer = "vCenter_Server"
$User = "your_username"
$Password = "your_password"
# Connect to vCenter
Connect-VIServer -Server $vCenterServer -User $User -Password $Password

# Retrieve all VMs in the vCenter
$vms = Get-VM

# Loop through each VM and create a snapshot
foreach ($vm in $vms) {
    $snapshotName = "$($vm.Name)_Snapshot_$(Get-Date -Format yyyyMMdd_HHmmss)"
    New-Snapshot -VM $vm -Name $snapshotName -Description "Automated snapshot taken on $(Get-Date)"
}

# Disconnect from the vCenter
Disconnect-VIServer -Server $vCenterServer -Confirm:$false

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.

Ready when you are.

Try ServerEngine free for 7 days.