This was a script I wrote to take a snapshot every day, and keep 5 days worth for a third party clients VM in our environment.
Although this is not the ideal way of having a backup, the business were happy with this low cost approach.
[cc lang=”Powershell”]
##################################################
# #
# PowerCLI Script to Run Daily to Snapshot and #
# Keep 5 days worth of Snapshots as per customer#
# request. #
# NO’K #
##################################################
Set-ExecutionPolicy Unrestricted
$vCenter = “10.10.10.100”
$vm = “VMNameHere”
$date = Get-Date -Format dd_MM_yyyy_hh:mm
Set-PowerCLIConfiguration -InvalidCertificateAction
# Load PowerCLI Module
Add-PSSnapin VMware.VIMAutomation.Core
# Connect to vCentre
Connect-VIServer -Server $vCenter
# Connect to VM & Take Snapshot 10-20 Mins Approx
New-Snapshot -Name DailySnapshot_$date -Description “Daily Snapshot $date” -Memory -Server $vCenter -VM $vm
# Purge Old Snapshots > 5 days
Get-Snapshot $vm | Where-Object { $_.Created -lt (Get-Date).AddDays(-5) } | Remove-Snapshot -Confirm:$false
[/cc]