Wednesday, December 14, 2016

Easy way to determine UEFI or Legacy BIOS from PowerShell

PowerShell script which determines the underlying system firmware (BIOS) type - either UEFI or Legacy BIOS:

if (Test-Path $env:windir\Panther\setupact.log) {(Select-String 'Detected boot environment' -Path "$env:windir\Panther\setupact.log"  -AllMatches).line -replace '.*:\s+'else {if (Test-Path HKLM:\System\CurrentControlSet\control\SecureBoot\State) {"UEFI"} else {"BIOS"}}

PowerShell script which determines EFI partition:

Get-WmiObject  -query 'Select * from Win32_DiskPartition Where Type = "GPT: System"' | select Name, Index, Bootable, BootPartition,PrimaryPartition, @{n="SizeInMB";e={$_.Size/1MB}}

You may need this information for VMware/Physical machines to Azure with Azure Site Recovery scenario (or even Hyper-V Gen 2 VMs where you don't have actual access to Hyper-V itself, ex. 3rd party IaaS provider). As of today UEFI partitions are not supported in these scenarios and you will end with
ERROR ID 78006
The requested operation did not complete. 
Provider error code: 95185 Provider error message: Protection could not be enabled. Provider error possible causes: Enable protection failed for the source disks {GUID} on the source machine <Hostname> (IP Address). UEFI partitions are not supported. Provider error recommended action: UEFI partitions are not supported. See for the pre-requisites.
Check the provider error for more details.
Resolve the issue as recommended in the provider error details.