加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 05:42:27 所属栏目:Windows 来源:网络整理
导读:我正在尝试通过Power Shell远程应用Hyper-V快照.我正在关注 Ben Armstrong’s guide. 顺便说一下,我在Server 2008 R2中. 简而言之: 连接到远程服务器: $password = ConvertTo-SecureString "password" -AsPlainText -Force$cred = New-Object System.Manag
我正在尝试通过Power Shell远程应用Hyper-V快照.我正在关注 Ben Armstrong’s guide.

顺便说一下,我在Server 2008 R2中.

简而言之:

连接到远程服务器:

$password = ConvertTo-SecureString "password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("domainuser",$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 rootvirtualization Msvm_VirtualSystemManagementService -computername $HyperVServer

# Get the virtual machine object
$VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "rootvirtualization" -computername $HyperVServer

# Find the snapshot that we want to apply
$Snapshot = gwmi -Namespace rootvirtualization -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时无法远程工作

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读