答案1
Select-String
处理bcdedit
输出应该与语言无关。
我的德语区域设置输出:
> bcdedit
Windows-Start-Manager
---------------------
Bezeichner {bootmgr}
device partition=\Device\HarddiskVolume1
description Windows Boot Manager
locale de-DE
inherit {globalsettings}
default {current}
...snip...
脚本的修改版本如下:
function GetBootMgrPartitionPath() {
$bootMgrPartitionPath = bcdedit /enum `{bootmgr`} |
Select-String -Pattern '\{bootmgr\}' -context 1|
ForEach-Object { ($_.Context.PostContext.Split('=')[1]) }
if ($bootMgrPartitionPath -eq $null){
throw "Could not get the partition path of the {bootmgr} BCD entry"
}
return $bootMgrPartitionPath
}
返回此:
> GetBootMgrPartitionPath
\Device\HarddiskVolume1
答案2
好的,我自己发现了:
function GetBootMgrPartitionPath()
{
$match = & bcdedit /enum `{bootmgr`} | Select-String "device\s*partition=(?<path>[\w*\\]*)"
$bootMgrPartitionPath = $match.Matches[0].Groups[1].Value
if ($bootMgrPartitionPath -eq $null)
{
throw "Could not get the partition path of the {bootmgr} BCD entry"
}
return $bootMgrPartitionPath
}