← script library

Automate VMware vSphere VM Snapshot Creation

VMware & vSphereJanuary 8, 2025

In this post, you will learn how to create a PowerShell script that automates the process of taking snapshots of virtual machines in VMware vSphere. This script can save you time and ensure consistent backup practices.

powershell
# Define your vCenter Server credentials
$vcServer = "vcenter_server_IP_or_FQDN"
$vcUser = "username"
$vcPassword = "password"
# Connect to the vCenter Server
Connect-VIServer -Server $vcServer -User $vcUser -Password $vcPassword

# Define the virtual machine name and snapshot details
$vmName = "Your_VM_Name"
$snapshotName = "Automated_Snapshot_" + (Get-Date -Format "yyyyMMdd_HHmmss")
$snapshotDescription = "Snapshot created on " + (Get-Date)
# Get the virtual machine object
$vm = Get-VM -Name $vmName

# Create a snapshot of the specified VM
New-Snapshot -VM $vm -Name $snapshotName -Description $snapshotDescription -Memory $false -Quiesce $true

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.