Wednesday, April 16, 2014

Script to delete vmware snapshots, batch file to run as a scheduled task

Run this from power shell to delete your snapshots:

Connect-VIServer vsphereserver

Get-vm "guest vm" | get-snapshot | Remove-Snapshot -confirm:$false

save it as something .ps1

Batch file:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -psc "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -c ". \"C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-VIToolkitEnvironment.ps1\";C:\vmwarescript\yourpowershellscript"


Machine running this will need VMWare powercli installed.  

If your user is not an admin that will be running the script as a scheduled task it will need logon as batch job and service rights and explicit rights to the CMD.exe file in C:\windows\system32.

No comments:

Post a Comment