When configuring the Windows boot configuration database (BCD), we’ve always had BCDEDIT.EXE, which is a reasonable tool to use but not a lot of fun to automate, e.g. finding and removing a specific item from a script. People have managed to wrap this in a PowerShell script, but parsing the output of executables isn’t much fun.
There is also a set of WMI classes that exposes the BCD configuration, but it’s not really like most other WMI classes. It’s more like writing code, even when using PowerShell, in that you have to explicitly open and close the BCD, deal with the specific BCD element types, etc., which makes it much more difficult. Possible, sure, but still not much fun.
So, I was happy to see that there is a new Microsoft.Windows.Bcd.Cmdlets module in Windows 11. For whatever reason, it’s completely undocumented, but it includes a number of cmdlets:
If anything, this looks like too much — duplicating the class structure from WMI and command lines from BCDEDIT almost too closely, meaning that this too is going to be complex. But let’s try it anyway.
First, let’s try Get-BcdEntry:
OK, that’s not too bad, that’s the BCD entry that was used to boot the current OS. (There aren’t any options to ask for all the BCD entries.) But if you actually look at the object, you can see that it’s just formatted nicely — the underlying object is similar to what you would get from WMI.
If you look more closely at the properties, there is some promise:
So the “Elements” property is the most useful here, as it lets you get the individual property names and values from the BCD entry. But what if you want all of the BCD entries, since there are always more than one? The Get-BcdStore cmdlet returns an array of them:
And we can inspect that array:
But it’s not ideal, as you then have to inspect the array of elements to see the detail for each one. Doable via some nested loops, e.g. PowerShell code, not as straight-forward to query and manipulate directly. Here’s an example to remove a BCD entry with a specific name:
Nice that it prompts for confirmation (you could specify -Force to avoid that). The code overall isn’t awful, but it’s definitely “code” and not simple “script”, e.g. what I’d like to see:
Get-BcdEntry -Description “Windows Boot Manager” | Remove-BcdEntry
I would think the PowerShell team would really gnash their teeth over this one. It’s just not “Powershell-y.”
Ah, well, it’s at least a little better than the alternatives. But there are additional downsides:
- This was only added in Windows 11 21H2, not in Windows 10 21H2. This isn’t surprising since Windows 10 will likely not get any new features at all, ever again.
- This wasn’t added to Windows PE, so you can’t use the new module there. And where would I normally want to be doing BCD manipulation? In Windows PE. Sigh.
Categories: Windows 11