Chris Warwick has released GetUEFI, a new UEFI-centric tool for Windows systems, on Github.
GetUEFI: Determine Firmware Type (UEFI or BIOS)
Chris Warwick, @cjwarwickps, November 2015
The function in this module determines the underlying system firmware (BIOS) type – either UEFI or Legacy BIOS. See the comments at the end of the script file for further detailed notes and references. This Get-FirmwareType function uses three techniques (in helper functions) to determine the underlying machine firmware type, either checking the firmware type recorded by Windows setup or using one of two Win32 APIs that are called from PowerShell through a compiled (Add-Type) class using P/Invoke. The first method relies on the fact that Windows setup detects the firmware type as a part of the Windows installation routine and records its findings in the setupact.log file in the \Windows\Panther folder. It’s a trivial task to use Select-String to extract the relevant line from this file and to pick off the (U)EFI or BIOS keyword it contains. This technique should work on all versions on Windows. For Windows 7/Server 2008R2 and above, the GetFirmwareEnvironmentVariable Win32 API (designed to extract firmware environment variables) can be used. This API is not supported on non-UEFI firmware and will fail in a predictable way when called – this will identify a legacy BIOS. On UEFI firmware, the API can be called with dummy parameters, and while it will still fail the resulting error code will be different from the legacy BIOS case. For Windows 8/Server 2012 and above there’s a more elegant solution in the form of the GetFirmwareType() API. This returns an enum (integer) indicating the underlying firmware type. Get-FirmwareType will use one of the above methods based on the version of the Windows OS. Alternatively, the method can be explicitly selected using the -QueryType parameter.
Sounds useful. But what a mess, just to determine firmware type. You’d think that Microsoft Windows team would have a GetFirmwareType() API with Hungarian-flavored versions of BIOS, UEFI, and all the other flavors that embedded WinCE and embedded NT use.
More information:
https://github.com/ChrisWarwick/GetUEFI
