1

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

  • Do you really want to parse BCDEDIT, or are you simply looking for the boot partition drive letter? (Get-Partition |? IsBoot).DriveLetter – Matthew Wetmore Jun 11 '18 at 6:14
  • @MatthewWetmore I really need to parse the output. – SuperJMN Jun 11 '18 at 8:16
1

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
| improve this answer | |
0

OK, found out myself:

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
}
| improve this answer | |
  • Are you absulotely sure device isn't also localized in some languages? My answer tries to get the relative position. – LotPings Jun 6 '18 at 17:10
  • It isn't in Spanish at least. How else would I identify it? 😐 – SuperJMN Jun 6 '18 at 20:30
  • 1
    Just by position like my script does. – LotPings Jun 6 '18 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.