Hello can someone provide me script for deleting snapshot in one shot from 90 servers through powercli script.
Hi, can try this.
#Copy the VM names into VMnames.txt file under C:\VMnames.txt and run it, Before running below lines connect to all the vCenter Server where your 50 VMs are residing.
$VMs = Get-Content -LiteralPath C:\VMnames.txt
$snap = Get-VM $VMs | get-snapshot | Where { $_.Created -lt (Get-Date).AddDays(-90)}
remove-snapshot -snapshot $snap -confirm:$false
"servers" as in you have 90 VMs or as in you have 90 ESXi hosts?
Either way, are they managed by the same vCenter Server, or by multiple vCenter Servers?
I want to delete old snapshot from 90 VM's in one shot through powercli .Appreciate for your quick update.
VMs managed by the same vCenter Server or by multiple vCenter Servers?
All 90 VM's are managed by same vcenter.
Hi Asif787
Connect to any vCenter Server and Run below script, It will delete all the snapshot older than 90 days on all the VMs for connected vCenter Server.
#vCenter Server wise script
$snap = Get-VM | get-snapshot | Where { $_.Created -lt (Get-Date).AddDays(-90)}
remove-snapshot -snapshot $snap -confirm:$false
Note: I would not recommend to run the script for all the VMs in a VC, better run cluster-wise
#Cluster-wise script
$cluster = "your_cluster_name"
$snap = Get-cluster $cluster | Get-VM | get-snapshot | Where { $_.Created -lt (Get-Date).AddDays(-90)}
remove-snapshot -snapshot $snap -confirm:$false
Hello yosingh,
I don't want to delete snapshot from all vm's or cluster wise..i have 90VM's I want to delete old vm's from those 90 VM's only.
please let me know if there is any script to delete old snapshot from specific list of vm's.
Unless the 90 VMs have something in common such as part of their name, you will probably need to create a CSV file and have your script read that file.
Hi, can try this.
#Copy the VM names into VMnames.txt file under C:\VMnames.txt and run it, Before running below lines connect to all the vCenter Server where your 50 VMs are residing.
$VMs = Get-Content -LiteralPath C:\VMnames.txt
$snap = Get-VM $VMs | get-snapshot | Where { $_.Created -lt (Get-Date).AddDays(-90)}
remove-snapshot -snapshot $snap -confirm:$false
Thank you so much yosingh ...I really appreciate your quick help.
Thank you so much scot28tt for your quick response .I have got the correct script answer from yosingh.
Hi YoSingh,
Thank you for the script.
Can I use the same script for snapshot removal as per age limit.
Age limit set to 120 days or 180 days.
Please reply. Thank You in advance.