Deleting a Snapshot with Powershell


i have been writing scripts automatically take snapshots everynight.  those work fine need ability delete snapshots via powershell , problem is.  here deletion script:

# prompt hyper-v server use  $hypervserver = 'hyperv machine'     # prompt virtual machine use  $vmname = '01-vm'     # prompt name of snapshot delete  $snapshotname = 'dailybackup'     # management service  $vmms = gwmi -namespace root\virtualization msvm_virtualsystemmanagementservice -computername $hypervserver     # virtual machine object  $vm = gwmi msvm_computersystem -filter "elementname='$vmname'" -namespace "root\virtualization" -computername $hypervserver     # find snapshot want delete  $snapshot = gwmi -namespace root\virtualization -query "associators of {$vm} assocclass=msvm_elementsettingdata resultclass=msvm_virtualsystemsettingdata" | {$_.elementname -eq $snapshotname} | select -first 1     # delete snapshot  $result = $vmms.removevirtualsystemsnapshot($snapshot)

i got script here : http://blogs.msdn.com/b/virtual_pc_guy/archive/2011/10/20/deleting-a-snapshot-via-powershell-hyper-v.aspx

my problem when hit line 

$snapshot = gwmi -namespace root\virtualization -query "associators of {$vm} assocclass=msvm_elementsettingdata resultclass=msvm_virtualsystemsettingdata" | {$_.elementname -eq $snapshotname} | select -first 1

i error gwmi: not supported

all appreciated!!

you have hyper-v 2008 r2. 

you therefore need delete snapshots using wmi direct hyper-v server vm is, or must use scvmm.  and, must power off vms after deleting snapshots (unless reverting).

in thread have been given hyper-v 2012 cmdlet commands , scvmm cmdlet commands.

personally, if have scvmm, why not use it?

your error in wmi script in portion of pipeline:

gwmi -namespace root\virtualization -query "associators of {$vm} assocclass=msvm_elementsettingdata resultclass=msvm_virtualsystemsettingdata"

the assumption of command running script.  assumes running script locally on hyper-v server itself, in spite of asking , previous lines targeting remote system.

try this:

$snapshot = gwmi -namespace root\virtualization -query "associators of {$vm} assocclass=msvm_elementsettingdata resultclass=msvm_virtualsystemsettingdata" -computername $hypervserver | {$_.elementname -eq $snapshotname} | select -first 1 

notice added -computername



brian ehlert
http://itproctology.blogspot.com
learn. apply. repeat.
disclaimer: attempting change of own free will.



Windows Server  >  Hyper-V



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file