Получение данных из BCEDIT с помощью Powershell

Мне нужно получить некоторые данные из указанной записи BCD. Мне нужна запись, идентифицированная идентификатором {bootmgr} .

Из этой записи я хотел бы получить "G:". См. Снимок экрана.

Как мне проанализировать вывод, чтобы сделать это?

УВЕДОМЛЕНИЕ: Я бы хотел, чтобы он работал независимо от глобализации системы, будь то испанский, английский, Китайский ...

Есть ли лучший способ справиться с записями BCD, чем использование BCDEDIT в PowerShell?

enter image description here

1
задан 6 June 2018 в 18:40
2 ответа

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
1
ответ дан 3 December 2019 в 23:15

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
}
0
ответ дан 3 December 2019 в 23:15

Теги

Похожие вопросы