2017-08-29 42 views
0

我想腳本消除/ OEM分區的備份(這只是將系統帶回過時的版本沒有實際使用)。Powershell&bcdedit:確定恢復分區

在很多系統上,使用DISKPART list partition返回更多recovery類型分區:一個是官方的Microsoft Recovery Tools分區(WinRE),另一個來自OEM。

第一步是安全地確定WinRE分區的位置。我沒有bcdedit找到任何直接的方式或PS以外:

$renv=(bcdedit /enum "{default}" | Select-String "^recoverysequence" | Out-String | Select-String "{.+}").Matches.Value 
(bcdedit /enum $renv | Select-String "^device" | Out-String | Select-String "\[.+\]").Matches.Value 

這將返回喜歡的字符串:

[\Device\HarddiskVolume1] 

,其中卷號爲Diskpart使用的分區。 (剩餘的恢復分區和OEM類型分區可以備份)。

這是識別WinRE分區的正確過程嗎?

有沒有更直的和/或更好的方法?

回答

1

除了有Lookbehind-RE
我dont't簡化了Select-String會看到一個更好的辦法ATM。

$renv=(bcdedit /enum "{default}" | Select-String "(?<=^recoverysequence\s+)({.+})").Matches.Value 
(bcdedit /enum $renv | Select-String "(?<=^device.+)\[.+\]").Matches.Value 
[\Device\HarddiskVolume5]