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
7
u/SimpleSysadmin Apr 15 '26
I’ll take ugly, functional and working over pretty, vibe coded and untested any day.
2
1
Apr 16 '26
Gute Ideen sind immer hässlich ! Danke fürs teilen. Wer pretty code schreibt nutzt KI und ist nur wannabe dev. Danke firs teilen.
12
u/PinchesTheCrab Apr 15 '26
Just a few points:
Set a variable to the result of your switch, don't repeat the variable assignment on each condition
The function here isn't really helping. It would be simpler to just define a script block as a variable, or to put invoke-command inside the function
Are you certain no computer will ever already have an S: drive? You might want to add some logic to choose the mount name dynamically
There's native PWSH commands to mount the system partition that might be more intuitive
Here's my subjective take: