One of my recent projects is to convert our remaining legacy systems from BIOS to UEFI. While setting up the task sequence, I needed to be able to test the system to make sure it was not already UEFI so the task sequence would end if it was.
The PowerShell script reads the setupact.log file and extracts if it is configured as BIOS or UEFI. I have included an unknown message in the event the log file does not exist or is inaccessible, which is what I encountered on one machine. For setting it up in a Configuration Manager task sequence, I set the sequence to look for a return code of 0, else it will return either a 1 or 2, which will fail the task sequence, and allow the admin to know why it failed from the console with the error code being returned.
You can download the script from my GitHub site.
<#
.SYNOPSIS
Check Boot Environment
.DESCRIPTION
This script reads the setupact.log file to determine if the system is configured for BIOS or UEFI.
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.142
Created on: 9/25/2020 11:59 AM
Created by: Mick Pletcher
Filename: BootEnvironment.ps1
===========================================================================
#>
Try {
$Output = (Get-Content -Path (((Get-ChildItem -Path ($env:windir + '\Panther') -Recurse -Filter setupact.log -ErrorAction SilentlyContinue)[0]).FullName) -ErrorAction SilentlyContinue | Where-Object {$_ -like "*Detected boot environment*"}).Replace("Detected boot environment:", "~").Split("~")[1].Trim()
If ($Output -eq 'BIOS') {
Write-Output 'BIOS'
Exit 0
} elseif ($Output -eq 'UEFI') {
Write-Output 'UEFI'
Exit 1
}
} Catch {
Write-Output 'Unknown'
Exit 2
}
0 comments:
Post a Comment