If You use virual machines actively, sometimes there is situation when there is too much snapshots.

hv_image002

System Center Virtual Machine Manager cannot delete the whole tree. It still could be done through the remote management console, but You can also use Hyper-V powershell library to do it.

Download link: https://pshyperv.codeplex.com/

To avoid installation errors, You first need to right-click downloaded file properties, and make “Unblock”:

unbl_image003

In my case I also needed to correct one string in menu.ps1, as described here. Maybe in Your case all will work without workarounds.

Using this library, You can delete snapshot tree on a remote server with this example code(remember that user still needs to have permissions to do this operation):

if (!(Get-Module -Name hyperv))
{
    import-module hyperv
}

Set-ExecutionPolicy "RemoteSigned" -Scope Process -Confirm:$false

Set-ExecutionPolicy "RemoteSigned" -Scope CurrentUser -Confirm:$false

# Set-ExecutionPolicy unrestricted -force

Get-Vmsnapshot -VM VMname -Server Servername -Root | remove-vmsnapshot -tree

a_image005

As a result of this script, after some time snapshots begin to dissappear

a1_thumb

and then will be all deleted:

a2_thumb

Of course in 2008 version, *.avhd files still will be there, and You need to put VM in “Save state” or turn them off to merge differencing disks and free hard disk space.

Click below to expand comments form..