Reputation: 590
How can I use Powershell to determine if a device is running in UEFI or Legacy boot mode and return a simple string that says "UEFI" or "Legacy"?
Upvotes: 2
Views: 7561
Reputation: 21
Run that on Powershell without elevation:
$env:firmware_type
Returns "UEFI" or "Legacy"
Upvotes: 2
Reputation: 18853
The below is for elevated, there might be ways to get it non-elevated, but you didn't specify if that was a requirement so here it is.
Run this in an elevated PowerShell:
$BootMode = bcdedit | Select-String "path.*efi"
if ($null -eq $BootMode) {
# I think non-uefi is \Windows\System32\winload.exe
$BootMode = "Legacy"
}else {
# UEFI is:
#path \EFI\MICROSOFT\BOOT\BOOTMGFW.EFI
#path \Windows\system32\winload.efi
$BootMode = "UEFI"
}
Write-Host "Computer is running in $BootMode boot mode."
If it has .efi
in the path, its UEFI mode. If it shows .exe
, it's the legacy boot if my memory serves me right.
Upvotes: 7