4

我正在尝试通过 PowerShell 远程应用 Hyper-V 快照。我正在遵循Ben Armstrong 的指南

顺便说一句,我在 Server 2008 R2 中。

简而言之:

连接远程服务器:

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

这工作得很好。我已经通过在机器上创建一个文件夹来测试这个远程连接。

应用快照:

$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)

我一个接一个地执行这些,找到VM和快照就好了,但是当我执行最终命令时,我的快照没有应用。它也不会失败,没有错误消息。

但是,在执行最终命令后,我确实得到了以下信息:

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

这个返回值Invalid state for this operation (32775)根据这个 MSDN page表示。这意味着什么?如何解决此问题以实际应用快照?

VM 当前处于运行状态,因此我在关闭 VM 并正确应用快照的情况下再次尝试。

如何强制快照应用于处于运行状态的 VM?

4

1 回答 1

1

文章明确指出:

需要注意的一点是,如果在您尝试应用快照时虚拟机正在运行,则此操作将失败 - 需要先关闭虚拟机或将其置于保存状态。

ApplyVirtualSystemSnapshot不能与正在运行的虚拟机远程工作

于 2014-06-08T11:46:30.703 回答