Мне нужно получить некоторые данные из указанной записи BCD. Мне нужна запись, идентифицированная идентификатором {bootmgr} .
Из этой записи я хотел бы получить "G:". См. Снимок экрана.
Как мне проанализировать вывод, чтобы сделать это?
УВЕДОМЛЕНИЕ: Я бы хотел, чтобы он работал независимо от глобализации системы, будь то испанский, английский, Китайский ...
Есть ли лучший способ справиться с записями BCD, чем использование BCDEDIT в PowerShell?
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
OK, выяснилось:
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
}