Cet article fait suite au guide :
« Sécuriser votre PC – Guide étape par étape pour la mise à jour des certificats Secure Boot 2023 – Partie 1 ».
Dans cette mise à jour, nous ajoutons un script PowerShell de collecte permettant d’évaluer automatiquement la conformité d’un poste Windows avant (ou après) la mise à jour des certificats Secure Boot 2023.
Ce script est particulièrement utile dans des contextes Intune / MECM / scripts de conformité.
Objectif du script :
Le script permet de déterminer si une machine est conforme concernant Secure Boot 2023, en vérifiant :
- l’activation de Secure Boot,
- la présence du certificat Windows UEFI CA 2023,
- l’état des clés Secure Boot côté registre,
- la présence de l’événement TPM ID 1808,
- les informations BIOS (fabricant / version).
Il retourne :
- un résultat JSON exploitable,
- un code de sortie compatible avec les règles de conformité (0 = conforme, 1 = non conforme).
Script PowerShell de collecte Secure Boot 2023 :
$IsCompliant = $true
$FailureReason = @()
# STEP 1: Secure Boot
try {
if (-not (Confirm-SecureBootUEFI)) {
$IsCompliant = $false
$FailureReason += "SecureBootDisabled"
}
}
catch {
$IsCompliant = $false
$FailureReason += "LegacyBIOS"
}
# STEP 2: Secure Boot CA 2023
$SBCA2023 = "NOTPresent"
try {
$db = Get-SecureBootUEFI -Name db -ErrorAction Stop
$dbText = [System.Text.Encoding]::ASCII.GetString($db.Bytes)
if ($dbText -match "Windows UEFI CA 2023") {
$SBCA2023 = "Present"
}
}
catch {}
if ($SBCA2023 -ne "Present") {
$IsCompliant = $false
$FailureReason += "SBCA2023Missing"
}
# STEP 3: Registry
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\SecureBoot\Servicing"
$UEFIStatus = "UNKNOWN"
$UEFICapableMeaning = "Unknown"
$UEFIError = "NotPresent"
$UEFIErrorEvent = "NotPresent"
if (Test-Path $regPath) {
$props = Get-ItemProperty $regPath -ErrorAction SilentlyContinue
$UEFIStatus = $props.UEFICA2023Status
$UEFIError = $props.UEFICA2023Error
$UEFIErrorEvent = $props.UEFICA2023ErrorEvent
switch ([int]$props.WindowsUEFICA2023Capable) {
0 { $UEFICapableMeaning = "CA2023NOTInDB" }
1 { $UEFICapableMeaning = "CA2023InDB" }
2 { $UEFICapableMeaning = "BootedWith2023" }
}
}
if ($UEFIStatus -ne "Updated") {
$IsCompliant = $false
$FailureReason += "UEFICA2023NotUpdated"
}
# STEP 4: TPM Event 1808
$Event1808 = "NotPresent"
$event = Get-WinEvent -FilterHashtable @{LogName='System'; ID=1808} -MaxEvents 1 -ErrorAction SilentlyContinue
if ($event) {
$Event1808 = "Present"
} else {
$IsCompliant = $false
$FailureReason += "TPM1808Missing"
}
# STEP 5: BIOS
$BIOSVersion = (Get-CimInstance Win32_BIOS).SMBIOSBIOSVersion
$BIOSMan = (Get-CimInstance Win32_BIOS).Manufacturer
# FINAL OUTPUT (IMPORTANT)
$result = [PSCustomObject]@{
Compliance = $IsCompliant
SBCA2023 = $SBCA2023
UEFICA2023Status = $UEFIStatus
TPMEvent1808 = $Event1808
WindowsUEFICA2023Capable = $UEFICapableMeaning
UEFICA2023Error = $UEFIError
UEFICA2023ErrorEvent = $UEFIErrorEvent
BIOSVersion = $BIOSVersion
BIOSMan = $BIOSMan
FailureReason = ($FailureReason -join ",")
}
$result | ConvertTo-Json -Compress
if ($IsCompliant) { exit 0 } else { exit 1 }
Ce script peut être utilisé :
- comme script de détection Intune,
- dans MECM (baseline),
- en exécution locale pour audit.
Conclusion :
Cette mise à jour complète la Partie 1 en apportant un outil concret de collecte et de conformité, indispensable pour préparer les environnements à l’échéance Secure Boot 2026.
Une prochaine mise à jour pourra couvrir :
- l’automatisation du déploiement,
- l’intégration Intune / MECM,
- la remédiation automatique.

0 commentaires