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

标签 powershell windows-server-2008 hyper-v

我正在尝试通过 PowerShell 远程应用 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

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

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 远程工作

关于powershell - 远程 PowerShell 脚本不应用 Hyper-V 快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18107665/

相关文章:

unix - 我怎么知道它是 Windows 服务器还是 Unix?

asp.net - 为什么我的 MVC 项目发布后无法运行?

.net - Windows Server 2008 上的最大 tcp/ip 连接数

winforms - Powershell - 一段时间后关闭表单

powershell - 如何将 powershell UTC 日期时间对象转换为 EST

powershell - 如何在 Visual Studio Code 中重置 PowerShell 运行空间

programming-languages - 如果我已经开始使用 PowerShell,要学习什么(脚本)语言?

python - 如何使用 python 脚本或任何命令在 hyper-v 上使用 WMIC 创建虚拟机?

windows - 在 Windows 10 中创建 Hyper-V 管理员组

c# - 模拟鼠标/键盘事件到 Hyper-V 虚拟机