Hello,
I have created snapshots for many VMs with the description:"Prior to install VM Hardware"
Can someone please tell me how to remove those snapshots that has a description : "Prior to install VM Hardware"
$vmlist = Get-Content "C:\VM\Snapshots\vmlists.txt"
foreach($VM in $VMlist) {
Get-Snapshot -VM $vm |
Remove-Snapshot -Confirm:$false
}
Disconnect-VIServer -Confirm:$false
Then you could try like this
foreach($VM in $VMlist) {
Get-Snapshot -VM $vm | where{$_.Description -eq 'Prior to install VM Hardware'} |
Remove-Snapshot -Confirm:$false
}
Disconnect-VIServer -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
foreach($VM in $VMlist) {
Get-Snapshot -VM $vm -Name 'Prior to install VM Hardware' |
Remove-Snapshot -Confirm:$false
}
Disconnect-VIServer -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD,
Thank you for your script. Your suggestion works for the snapshot that has the name: 'Prior to install VM Hardware',
Here my snapshot names are different for each VMs, but Description is same : 'Prior to install VM Hardware',
Hence, is it possible to delete the snapshot collecting that Description name: 'Prior to install VM Hardware',
Upload and share screenshots and images - print screen online | Snipboard.io
Then you could try like this
foreach($VM in $VMlist) {
Get-Snapshot -VM $vm | where{$_.Description -eq 'Prior to install VM Hardware'} |
Remove-Snapshot -Confirm:$false
}
Disconnect-VIServer -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD
The script works perfectly...
what is a general script i can use to delete snapshot from my environment?
What do you mean by "general"?
Remove all snapshots?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello Luc,
Quick question please can we remove Snapshot from the listed VMs but based on Date and time of the snap wich should be listed into the CVS file ?
Exemple for the Csv VM Name / Date / Time of Snap Creation /
Thanks in advance
The object returned by Get-Snapshot contains a property Created.
You could use a Where-clause to only select the snapshot corresponding with a specific DateTime.
Just be aware that specifying the correct time in your CSV might be inaccurate since a DateTime is very precise (sub-second).
I would approach this with a time interval based on the value in your CSV
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello,
For me I create a 3 lines script to remove all snapshot older then 3 days, but it looks like the log file not working, I get nothing in the file.
Do you have any suggestion ?
Connect-VIServer -server blablabla
With the RunAsync switch the snapshot removal becomes a background task, and hence not producing any output.
You could use Get-Task, wait till all background tasks are completed, and then capture the info in the object returned by Get-Task.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is a good thread.
Hello, could you please share with us the script after the modification. Im intrest in it.
Thanks