远程PowerShell脚本不适用Hyper-V快照

前端之家收集整理的这篇文章主要介绍了远程PowerShell脚本不适用Hyper-V快照前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试通过Power Shell远程应用Hyper-V快照.我正在关注 Ben Armstrong’s guide.

顺便说一下,我在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

根据this MSDN page,此返回值表示此操作的无效状态(32775).这是什么意思?如何修复此问题以实际应用快照?

VM当前处于运行状态,因此我再次尝试关闭VM并正确应用快照.

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

解决方法

文章明确指出:

One thing to be aware of is that this operation will fail if the virtual machine is running when you try to apply the snapshot – the virtual machine needs to be turned off or put into a saved state first.

ApplyVirtualSystemSnapshot在运行VM时无法远程工作

猜你在找的Windows相关文章