Question

I am constantly getting error 32775 (Invalid state for this operation) when I try to revert my VMs to latest snapshot using WMI. I am using the following code (which is provided on MSDN website by the way):

ManagementObject virtualSystemService = Utility.GetServiceObject(connectionScope,"Msvm_VirtualSystemManagementService");
ManagementBaseObject inParams =virtualSystemService.GetMethodParameters("ApplyVirtualSystemSnapshot");
ManagementObject vmSnapshot = GetLastVirtualSystemSnapshot(vm);
if (vmSnapshot != null)
{
    inParams["SnapshotSettingData"] = vmSnapshot.Path.Path;
    inParams["ComputerSystem"] = vm.Path.Path;
    ManagementBaseObject outParams = virtualSystemService.InvokeMethod("ApplyVirtualSystemSnapshot", inParams, null);
    if ((UInt32)outParams["ReturnValue"] == ReturnCode.Started)
    {
        if (Utility.JobCompleted(outParams, connectionScope))
        {
            Console.WriteLine("Snapshot was applied successfully.");

        }
        else
        {
            Console.WriteLine("Failed to apply snapshot.");
        }
    }
    else if ((UInt32)outParams["ReturnValue"] == ReturnCode.Completed)
    {
        Console.WriteLine("Snapshot was applied successfully.");
    }
    else
    {
        Console.WriteLine("Apply virtual system snapshot failed with error {0}", outParams["ReturnValue"]);
    }
}
else
{
    Console.WriteLine("No Snapshots!");
}

I can apply snapshots on the UI with no problem, and my VMs are in enabled state and are not doing anything. OS is Windows 2012. I can also print the name of snapshots and VMs so there are no problems in identifying machines and snapshots.

any ideas? Thanks, Shahab

Was it helpful?

Solution

Found out the problem, apparently the VM needs to be turned off if you want to apply your snapshots remotely! maybe it was too hard to mention that on MSDN website.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top