top of page

PowerShell | PowerCLI Snapshots

When managing server patching, we always add a snapshot to the server before

patching at let it stay there for about 3-4 days before removal to assure that we

don’t need to roll back. These are the scripts I use for creation, review, and removal.

Scripts assume you are already connected to your vCenter server. 

Get list of computers and check for snapshots by VM name

$Computers=Get-VM | Select -ExpandProperty Name
Foreach($Comp in $Computers){Get-VM $Comp | Get-Snapshot | select VM, Name, Created, SizeGB,description | Export-CSV C:\temp\All-Snaps-Review.csv -NoTypeInformation -Append
}


        
Create snapshot on multiple servers with 10 second interval, sources from file.

 

$VMs=Get-Content C:\temp\Snaps\Snapper.txt

#Loop Through Updated List and Create Snaps before Patch Window
Foreach($VM in $VMs){
   Get-VM $VM | New-Snapshot -name "Pre-Patch Snap" -Description "Script Created-Prior to Patching" -RunAsync -ErrorAction Stop  
   Sleep 10
}

 

 

Import list of computers, delete specific snapshot by name with 30 second interval

Suggest only having like 6 or less systems in source file as to not stress storage system.

SQL and File servers seem to take the longest, just an FYI.

 

$Computers = Get-Content C:\temp\Snaps\One.txt
Foreach($Comp in $Computers){
    Get-Snapshot -VM $Comp | Where{$_.Name -eq 'Pre-Patch Snap'} | Remove-Snapshot -RunAsync -Confirm:$False 
    sleep 30
}

 
         

bottom of page