I have been writing scripts to automatically take snapshots everynight. Those work fine but I also need the ability to delete snapshots via powershell and that is where my problem is. Here is my deletion script:
# Prompt for the Hyper-V Server to use $HyperVServer = 'Hyperv Machine' # Prompt for the virtual machine to use $VMName = '01-vm' # Prompt for the name of the snapshot to delete $SnapshotName = 'DailyBackup' # Get the management service $VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer # Get the virtual machine object $VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "root\virtualization" -computername $HyperVServer # Find the snapshot that we want to delete $Snapshot = gwmi -Namespace root\virtualization -Query "Associators Of {$VM} Where AssocClass=Msvm_ElementSettingData ResultClass=Msvm_VirtualSystemSettingData" | where {$_.ElementName -eq $SnapshotName} | select -first 1 # Delete the snapshot $result = $VMMS.RemoveVirtualSystemSnapshot($Snapshot)
I got this script from here : http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/10/20/deleting-a-snapshot-via-powershell-hyper-v.aspx
My problem is when I hit the line
$Snapshot = gwmi -Namespace root\virtualization -Query "Associators Of {$VM} Where AssocClass=Msvm_ElementSettingData ResultClass=Msvm_VirtualSystemSettingData" | where {$_.ElementName -eq $SnapshotName} | select -first 1
I get the error gwmi: not supported
All help is greatly appreciated!!