Powershell – Get Data from BCEDIT

bcdeditpowershell

I have to get some data from a specify BCD entry. The entry I want is the one identified by the {bootmgr} identifer.

From that entry, I would like to get the "G:". See the screenshot.

How do I parse the output to do it?

NOTICE: I would like it to work independently of the System Globalization may it be Spanish, English, Chinese…

Is there any better way to deal with BCD entries than using BCDEDIT within PowerShell?

enter image description here

Best Answer

Select-String processing bcdedit output should be language independent.

My German locale outputs:

> bcdedit

Windows-Start-Manager
---------------------
Bezeichner              {bootmgr}
device                  partition=\Device\HarddiskVolume1
description             Windows Boot Manager
locale                  de-DE
inherit                 {globalsettings}
default                 {current}
...snip...

This modfied version of your script:

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
}

returns this:

> GetBootMgrPartitionPath
\Device\HarddiskVolume1
Related Topic