I currently use DISKSHADOW
to remove shadow copies from our Hyper-V servers. To do this I have to log onto the server but psexec
doesn't work.
psexec \\hyper-v-server diskshadow
DISKSHADOW> Error reading from console. Win32 error: 0x6
The handle is invalid.
I think vssadmin
works doing the above, but I'd like to script this with PowerShell and slectively remove the shadow copies. Neither of these tools provide usable output in PowerShell.
I've done a bit of research but not found any way to query snapshots with PowerShell, either locally or remotely. I imagine doing this will involve use of the Get-WMIObject
CMDlet to query the relevant info from WMI, but I can only find the Win32_ShadowCopy.Create()
method.
EDIT: To be clear, what I would like are objects I can manipulate using PowerShell.
You can use the Get-WMIObject cmdlet to remotely remove shadow copies. The example below demonstrates how it might work. It should be noted that the Get-WMIObject cmdlet returned a null object in the case where there were not any remote shadow copies available. This means that might still need a combination of PowerShell remoting and the vssadmin tool to remotely create shadow copies.
On the target server (from an elevated command prompt), let's first create a shadow copy so that one is available:
From the management server:
You can do this remotely with diskshadow. To accomplish this, write a batch file containing the wanted commands and place it somewhere on the target server, then:
psexec \\remotehost diskshadow /s C:\path\to\script.bat
. You can also use a network location for the path.