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

SuperJMN
  • 151
  • 2
  • 9

2 Answers2

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
SuperJMN
  • 151
  • 2
  • 9
LotPings
  • 1,015
  • 7
  • 12
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
}
SuperJMN
  • 151
  • 2
  • 9