r/PowerShell • u/Fallingdamage • Apr 15 '26
Script Sharing Powershell Function to survey domain environments for SecureBoot Updates
I wanted to share a script I put together back in november. If you have a smaller environment and want to quickly identify which devices may or may not have the new 2023 secure boot Certs and Bootloaders installed, you can use this method to generate a report.
Function Get-UEFICertVersion {
$machine = $env:COMPUTERNAME
switch (Confirm-SecureBootUEFI) {
$true {
switch (([System.Text.Encoding]::ASCII.GetString((Get-SecureBootUEFI db).bytes) -match 'Windows UEFI CA 2023')) {
$true {$uefiVer = "Windows UEFI CA 2023"}
$false {$uefiVer = "Windows UEFI CA 2011"}
default {$uefiVer = "-- unable to determine"}
}
}
$false {$uefiVer = "Secureboot Not Enabled"}
default {$uefiVer= "Error Occurred"}
}
mountvol.exe S: /s;
$BootloaderCert = (Get-PfxCertificate -FilePath "S:\EFI\Microsoft\Boot\bootmgfw.efi" | Select-Object -Property Issuer).Issuer
mountvol.exe S: /d
$WinVer = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name DisplayVersion).DisplayVersion
$WinBuild = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name CurrentBuild).CurrentBuild
$survey = @()
$results = New-Object PSObject -Property @{
ComputerName = $machine;
User = "Unknown";
WindowsVersion = $WinVer;
BuildNumber = $WinBuild;
UEFIVersion = $uefiVer;
Bootloader = $BootloaderCert
}
$survey += $results
Write-Output $survey
}
$computers = (Get-ADComputer -Filter 'operatingsystem -like "*Pro*"' -Properties Name, Description | select Name, Description)
$SecureBootAudits = (Invoke-Command -Computername $computers.Name -ScriptBlock ${function:Get-UEFICertVersion} -ErrorAction SilentlyContinue | Select ComputerName, User, WindowsVersion, BuildNumber, UEFIVersion, Bootloader)
Foreach ($computer in $computers) {$SecureBootAudits | Where-Object {$_.ComputerName -eq $computer.Name} | ForEach-Object {$_.User = $Computer.Description}}
$SecureBootAudits | ConvertTo-Csv | Out-File C:\Temp\SB_Results2.csv That is all. Its not pretty, but it works.
30
Upvotes
View all comments
Show parent comment
1
u/PinchesTheCrab Apr 17 '26
Thanks for pointing that out, that's super weird. I don't normally use a true/false value for a switch (I started from the OP's code and worked backwards), so I hadn't seen this behavior.
I'm not sure if this is actually evaluating these conditions as strings, or just using PWSH's truthiness. Regardless, all four match, which is not ideal if one needs to actually just act on booleans:
Even swapping it to an IF statement doesn't seem to help a lot:
In the end I'm okay with truthiness in this particular example, but if I wanted to be 100% sure I'd check the type. PWSH is weird.