删除卷影副本远程

我目前使用DISKSHADOW从我们的Hyper-V服务器中删除卷影副本。 为此,我必须login到服务器,但psexec不起作用。

 psexec \\hyper-v-server diskshadow DISKSHADOW> Error reading from console. Win32 error: 0x6 The handle is invalid. 

我认为vssadmin正在执行上述操作,但是我想用PowerShell编写脚本并select性地删除卷影副本。 这些工具都不能在PowerShell中提供可用的输出。

我已经做了一些研究,但没有find任何方式来查询本地或远程的PowerShell快照。 我想这样做会涉及使用Get-WMIObject CMDlet从WMI查询相关信息,但我只能findWin32_ShadowCopy.Create()方法。

编辑:要清楚,我想要的是我可以使用PowerShell操纵的对象。

您可以使用Get-WMIObject cmdlet远程删除卷影副本。 下面的例子演示了它是如何工作的。 应该注意的是,在没有任何远程卷影副本可用的情况下,Get-WMIObject cmdlet返回空对象。 这意味着可能仍然需要PowerShell远程处理和vssadmin工具的组合来远程创build卷影副本。

在目标服务器上(从提升的命令提示符下),让我们先创build一个卷影副本,以便可用:

 vssadmin create shadow /for=c: 

从pipe理服务器:

 $shadowCopies = Get-WMIObject -Class Win32_ShadowCopy -Computer <TARGET SERVER NAME> $shadowCopies | % {$_.DeviceObject} # Lists out just the names of the copies $shadowCopies | Get-Member -View All # Lists all members even hidden ones such as "delete" $shadowCopies[0].Delete() # Deletes the first shadow copy when more than one exists $shadowCopies.Delete() # Works when only a single shadow copy exists 

您可以使用磁盘远程执行此操作。 要做到这一点,编写一个包含所需命令的batch file,并将其放置在目标服务器上的某个位置,然后执行以下命令: psexec \\remotehost diskshadow /s C:\path\to\script.bat 。 您也可以使用path的networking位置。