2013-01-08 35 views
15

我嘗試使用Windows 7中的Windows Power Shell創建和訪問卷影複製快照。我發現可以通過以前的superuser question使用以下內容創建快照:從PowerShell中訪問卷影副本(VSS)快照

(Get-WmiObject -list win32_shadowcopy).create("C:\","ClientAccessible") 

我無法找到這表明它可以設置一個卷影副本「暴露」,以便它可以映射到使用WMI一個驅動器號的任何文件。在同一問題中鏈接的article顯示使用連接來訪問快照的黑客攻擊。

當我嘗試訪問符號鏈接,我得到如下:

PS C:\Windows\system32> ls C:\shadowcopy 
Get-ChildItem : The parameter is incorrect. 

At line:1 char:3 
+ ls <<<< C:\shadowcopy 
    + CategoryInfo   : ReadError: (C:\shadowcopy:String) [Get-ChildItem], IOException 
    + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand 

試圖訪問快照直接給出如下:

PS C:\Windows\system32> ls '\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy14' 
Get-ChildItem : Paths that begin with \\?\GlobalRoot are internal to the kernel and should not be opened by managed applications. 
At line:1 char:3 
+ ls <<<< '\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy14' 
    + CategoryInfo   : NotSpecified: (:) [Get-ChildItem], ArgumentException 
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.GetChildItemCommand 

我如何從一個訪問VSS快照PowerShell腳本?

回答

23

你是如何創建符號鏈接的?作爲該文章中介紹,你必須以反斜槓指定設備路徑:

$s1 = (Get-WmiObject -List Win32_ShadowCopy).Create("C:\", "ClientAccessible") 
$s2 = Get-WmiObject Win32_ShadowCopy | Where-Object { $_.ID -eq $s1.ShadowID } 

$d = $s2.DeviceObject + "\" # <-- this here 

cmd /c mklink /d C:\shadowcopy "$d" 

在此之後,我能夠訪問安裝C:\shadowcopy就好了卷影副本。

要卸載影子副本調用$s2.Delete(),正如@KeyszerS在評論中指出的那樣。

+3

尾隨的「\」是我錯過的關鍵部分。 – jordanm

+5

對於未來的讀者,下面是如何刪除卷影副本:''vssadmin delete shadows/Shadow =「」$($ s2.ID.ToLower())「」/ Quiet「| iex'然後'Remove-Item c:\ shadowcopy -Confirm:$ false -Force'。在您使用影子副本工作之後放置這些代碼。 –

+0

工程就像一個魔術。 –