none
Apply Checkpoint using PowerShell RRS feed

  • Question

  • How do I use MSVM_VirtualSystemSnapshotService.ApplySnapshot() or just how do I monitor the job to apply a checkpoint/snapshot on Windows Server 2012 using PowerShell 2.0?  I am new to powershell and think I am missing some basic understanding.

    I am trying to setup a test environment and have been following the 2011 post by Virtual PC Guy. blogs.msdn.com/b/virtual_pc_guy/archive/2011/10/19/applying-a-snapshot-via-powershell-hyper-v.aspx

    However, this was clearly written for Server 2008 and I am using Server 2012.  The MSVM_VirtualSystemManagementService no longer has a method ApplyVirtualSystemSnapshot(MSVM_ComputerSystem, MSVM_VirtualSystemSettingData).  Instead I found the Hyper-V WMI V2 classes; like MSVM_VirtualSystemSnapshotService with the description "Service to create, apply, and destroy snapshots of virtual machines."  The ApplySnapshot method has 2 parameters; MSVM_VirtualSystemSettingData [in] and MSVM_ConcreteJob [out].  Ultimately, I think I correctly modified the script to find and apply the snapshot with the exception that I can't get any details about the job.

    If I pass a $null object to ApplySnapshot then it will run and return 4096, indicating the job is in progress.  I can check Hyper-V Manager and the checkpoint/snapshot was indeed applied.  However, I can't get any details about the job.  If I try,

    $VMSS = Get-WMiObject -class Msvm_VirtualSystemSnapshotService -namespace $VM_namespace

    ...

    $Snapshot = $VM.GetRelated("Msvm_VirtualSystemSettingData") | where {$_.ElementName -eq $VM_snapshot} | select -first 1

    ...

    $output_job = $null

    $result = $VMSS.ApplySnapshot($Snapshot, $output_job)

    $result

    Then I get, Job: \\computername\root\virutalization\v2:Msvm_ConcreteJob.InstanceID="..." ReturnValue: 4096.

    And ($output_job -eq $null) returns TRUE, and ($result.job) returns the instance ID, and ($result.job.instanceid) retuns nothing, and (Get-Job -InstanceID $result.job) throws an error that it can't convert \\computername\root\virtualization\v2:Msvm_concretejob.InstanceID="..." to type System.Guid.

    If I try

    $output_job = New-Object System.Management.ManagementClass "Msvm_ConcreteJob"

    $result = $VMSS.ApplySnapshot($Snapshot, $output_job)

    Then I get an "Invalid method Parameter(s)" error and WMIMethodException.  I get the same if $output_job is a "CIM_ConcreteJob".

    It is my understanding that [ref] is not used for objects, and I tried ApplySnapshot($Snapshot, [ref]$output_job)...  I also tried many variations of ApplySnapshot($Snapshot, ($output_job)) or ApplySnapshot $Snapshot ($output_job) or ApplySnapshot(($Snapshot),($output_job))...

    Other details: my VM hosts are running Server 2012 and my TFS build server is on Server 2008.  I want to add the script to the build definition to deploy a clean test environment and then start the MTM test plan.  There may be other ways to do this, and I am prepared to try them; but I am too stuborn to abandon this script when it is so close.  I want to monitor the job so I know if the test environment is ready to deploy and run the tests.

    Last night, I started wondering if I was creating a job object on the 2008 server that I couldn't pass to the 2012 server.  But I can't find a way to create the job object remotely.  And I get the same error when running the script from the 2008 server with remote GWMI calls to 2012 as I do from running the script locally on the 2012 VM host server.  So, there is some other issue that I don't understand.  I have ignore stuff on Google saying to run Get-WmiObject -AsJob because the ApplySnapshot method clearly provides the job as output.

    Can someone help me get this script running?  Thanks in advance!!!

    Thursday, November 7, 2013 4:21 PM