Remote PowerShell script does not use Hyper-V snapshot

I am trying to remotely apply a Hyper-V snapshot through PowerShell. I follow Ben Armstrong's Guide .

By the way, I am on a 2008 R2 server.

In a nutshell:

Connection to a remote server:

$password = ConvertTo-SecureString "password" -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ("domain\user", $password) Enter-PSSession -Computer computerName -Credential $cred 

This works great. I checked this remote connection by creating a folder on the computer.

Snapshot Application:

 $HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)" # Prompt for the virtual machine to use $VMName = Read-Host "Specify the name of the virtual machine" # Prompt for the name of the snapshot to apply $SnapshotName = Read-Host "Specify the name of the snapshot to apply" # 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 apply $Snapshot = gwmi -Namespace root\virtualization -Query "Associators Of {$VM} Where AssocClass=Msvm_ElementSettingData ResultClass=Msvm_VirtualSystemSettingData" | where {$_.ElementName -eq $SnapshotName} | select -first 1 # Apply the snapshot $VMMS.ApplyVirtualSystemSnapshot($VM, $Snapshot) 

I execute them one at a time, he finds the virtual machine and the snapshot is just fine, but when I execute the last command, my snapshot is not applied. This also does not lead to any error messages.

I get the following, however, after running the final command:

 __GENUS : 2 __CLASS : __PARAMETERS __SUPERCLASS : __DYNASTY : __PARAMETERS __RELPATH : __PROPERTY_COUNT : 1 __DERIVATION : {} __SERVER : __NAMESPACE : __PATH : ReturnValue : 32775 

This return value indicates Invalid state for this operation (32775) according to this MSDN page . What does it mean? How to fix this to apply a snapshot?

Currently, the virtual machine is operational, so I tried to turn off the VM again and the snapshot was applied correctly.

How to forcibly apply a snapshot to a virtual machine in working condition?

+4
source share
1 answer

The article clearly states that:

One thing to be aware of is that this operation will fail if the virtual machine is running while trying to apply a snapshot - you must first turn off the virtual machine or put it in a saved state.

ApplyVirtualSystemSnapshot does not work remotely with VM startup

+1
source

Source: https://habr.com/ru/post/1495771/


All Articles