VMware Cloud Community
Asif787
Enthusiast
Enthusiast
Jump to solution

Need to delete snapshot from 90 servers in one shot through powercli

Hello can someone provide me script for deleting snapshot in one shot from 90 servers through powercli script.

1 Solution

Accepted Solutions
yosingh
Enthusiast
Enthusiast
Jump to solution

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

View solution in original post

11 Replies
scott28tt
VMware Employee
VMware Employee
Jump to solution

"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?


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Asif787
Enthusiast
Enthusiast
Jump to solution

I want to delete old snapshot from 90 VM's in one shot through powercli .Appreciate for your quick update.

0 Kudos
scott28tt
VMware Employee
VMware Employee
Jump to solution

VMs managed by the same vCenter Server or by multiple vCenter Servers?


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
Asif787
Enthusiast
Enthusiast
Jump to solution

All 90 VM's are managed by same vcenter.

0 Kudos
yosingh
Enthusiast
Enthusiast
Jump to solution

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

Asif787
Enthusiast
Enthusiast
Jump to solution

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.

0 Kudos
scott28tt
VMware Employee
VMware Employee
Jump to solution

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.


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
yosingh
Enthusiast
Enthusiast
Jump to solution

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

Asif787
Enthusiast
Enthusiast
Jump to solution

Thank you so much yosingh ...I really appreciate your quick help.

0 Kudos
Asif787
Enthusiast
Enthusiast
Jump to solution

Thank you so much scot28tt for your quick response .I have got the correct script answer from yosingh.

0 Kudos
AmeyAbl4
Contributor
Contributor
Jump to solution

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.

0 Kudos