r/PowerShell • • 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

9 comments sorted by

View all comments

Show parent comment

6

u/Fallingdamage Apr 15 '26

Thanks. I learned some things from this. Always building out new examples and ways to do things well. Its one thing to read scripts and try to apply methods to your own work. Its another to actually see these kind of changes applied to your work by another person. 👍