I'm creating an application that analyzes the entries in the Boot Configuration Data (BCD).
I've tried with PowerShell, but it seems that it doesn't provide any cmdlets to deal with it. So, I've fallen back to .NET, espically C#.
I would like to have something obtain the BCD entries like this
var entries = bcd.GetEntries();
with entries being an IList<BcdEntry>
class BcdEntry
{
public string Name {get; set; }
IDictionary<string, IList<string>> Properties { get; set; }
}
The problem is that I don't know how to obtain the entries. Invoking BCDEdit is a possibility, but it requires to parse the output of the command, that is a tedious task.
I hope you can think of a solution for my problem.
A PSv4+ solution that parses
bcdedit.exe /enum
output into a list of custom objects:Note:
As LotPing observes,
bcdedit.exe
output is partially localized; specifically, the following items:Windows Boot Manager
isAdministrador de arranque de Windows
in Spanish)identifier
in English (e.g.,Identificador
in Spanish).For the sake of brevity, the code makes no attempt to map localized names to their US-English counterparts, but it could be done.
Also, the sample
bcdedit
output posted with this ServerFault question (a duplicate) suggests that there may be property names that are so long that they run into their values, without intervening whitespace and without truncation.If that is not just an artifact of posting, more work would be needed to handle this case; this article contains a list of property names.
[pscustomobject]
instances are used rather than instances of a customBcdEntry
class; in PSv5+, you could create such a custom class directly in PowerShell.The property values are all captured as string values, collected in a
[List[string]]
list (even if there's only 1 value); additional work would be required to interpret them as specific types;e.g.,
[int] $entries[1].Properties['allowedinmemorysettings'][0]
to convert string'0x15000075'
to an integer.Sample input / output:
Given
bcdedit.exe /enum
output such as this...... the above command yields this:
To process the entries programmatically:
Note:
$entries | ForEach-Object { <# work with entry $_ #> }
, i.e. using the pipeline is an option too, but if the list of entries is already in memory, aforeach
loop is faster.