Copiare e incollare questo script di esempio e modificarlo in base alle esigenze dell'ambiente:
<# . SINOSSI Mostra lo stato corrente dell'agente di orchestrazione dell'implementazione di avvio protetto.
.DESCRIPTION Fornisce visibilità in tempo reale sullo stato di avanzamento dell'implementazione: - Numero di onda corrente e dispositivi mirati - Aggiornamento dei dispositivi rispetto a quello in sospeso - Bucket bloccati che richiedono attenzione - Log attività recenti - Collegamento dashboard Esegui questa operazione in qualsiasi momento per verificare lo stato di avanzamento dell'implementazione.
.PARAMETER ReportBasePath Percorso della directory di report/stato utilizzata dall'agente di orchestrazione
.PARAMETER ShowLog Visualizzare le voci recenti del log (ultime 50 righe)
.PARAMETER ShowBlocked Visualizzare i dettagli dei contenitori bloccati
.PARAMETER ShowWaves Mostra la cronologia delle onde con i conteggi dei dispositivi
.PARAMETER Watch Aggiornare continuamente lo stato ogni N secondi
.PARAMETER OpenDashboard Aprire il dashboard HTML più recente nel browser
.EXAMPLE .\Get-SecureBootRolloutStatus.ps1 -ReportBasePath "C:\SecureBootReports"
.EXAMPLE .\Get-SecureBootRolloutStatus.ps1 -ReportBasePath "C:\SecureBootReports" -Watch 30
.EXAMPLE .\Get-SecureBootRolloutStatus.ps1 -ReportBasePath "C:\SecureBootReports" -OpenDashboard #>
[CmdletBinding()] param( [Parametro(Obbligatorio = $true)] [stringa]$ReportBasePath, [Parametro(Obbligatorio = $false)] [opzione]$ShowLog, [Parametro(Obbligatorio = $false)] [opzione]$ShowBlocked, [Parametro(Obbligatorio = $false)] [opzione]$ShowWaves, [Parametro(Obbligatorio = $false)] [int]$Watch = 0, [Parametro(Obbligatorio = $false)] [opzione]$OpenDashboard )
$ErrorActionPreference = "Stop" $DownloadUrl = "https://aka.ms/getsecureboot" $DownloadSubPage = "Esempi di distribuzione e monitoraggio"
# Note: This script has no dependencies on other scripts. # Per il set di strumenti completo, scarica da: $DownloadUrl -> $DownloadSubPage
# ============================================================================ # FUNZIONI HELPER # ============================================================================
function ConvertTo-Hashtable { param([Parameter(ValueFromPipeline = $true)]$InputObject) process { if ($null -eq $InputObject) { return @{} } if ($InputObject -is [System.Collections.IDictionary]) { restituisce $InputObject } if ($InputObject -is [PSCustomObject]) { $hash = @{} foreach ($prop in $InputObject.PSObject.Properties) { $hash[$prop. Name] = ConvertTo-Hashtable $prop. Valore } restituire $hash } if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string]) { restituire @($InputObject | ForEach-Object { ConvertTo-Hashtable $_ }) } restituire $InputObject } }
function Show-Status { $stateDir = Join-Path $ReportBasePath "RolloutState" $rolloutStatePath = Join-Path $stateDir "RolloutState.json" $blockedBucketsPath = Join-Path $stateDir "BlockedBuckets.json" Clear-Host Write-Host "" Write-Host ("=" * 80) -ForegroundColor Ciano Write-Host " SECURE BOOT ROLLOUT STATUS" -ForegroundColor Cyan Write-Host " $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor Gray Write-Host ("=" * 80) -ForegroundColor Ciano Write-Host "" # Controlla se l'attività di orchestrazione è in esecuzione $task = Get-ScheduledTask -TaskName "SecureBoot-Rollout-Orchestrator" -ErrorAction SilentlyContinue if ($task) { $taskState = $task. Stato $color = if ($taskState -eq "Running") { "Green" } elseif ($taskState -eq "Ready") { "Yellow" } else { "Red" } Write-Host "Attività programmata: " -NoNewline Write-Host $taskState -ForegroundColor $color } else { Write-Host "Attività programmata: " -NoNewline Write-Host "Non installato" -ForegroundColor gray } # Load rollout state if (-not (Test-Path $rolloutStatePath)) { Write-Host "" Write-Host "Stato implementazione non trovato. L'agente di orchestrazione potrebbe non essere ancora stato avviato". -Primo pianoColore giallo Write-Host "State path: $rolloutStatePath" -ForegroundColor gray Ritorno } $state = Get-Content $rolloutStatePath -Raw | ConvertFrom-Json | ConvertTo-Hashtable Write-Host "" Write-Host "STATO DELL'IMPLEMENTAZIONE" -Primo pianoColore giallo Write-Host ("-" * 40) $status = $state. Stato $statusColor = interruttore ($status) { "Completato" { "Verde" } "In Contrassegno" { "Ciano" } "NotStarted" { "Gray" } predefinito { "Bianco" } } Write-Host "Stato: " -NoNewline Write-Host $status -ForegroundColor $statusColor Write-Host "Onda corrente: $($state. CurrentWave)" Write-Host "Totale mirato: $($state. TotalDevicesTargeted)" Write-Host "Totale aggiornato: $($state. TotalDevicesUpdated)" se ($state. StartedAt) { Write-Host "Avviato: $($state. StartedAt)" } se ($state. LastAggregation) { Write-Host "Ultimo controllo: $($state. LastAggregation)" } se ($state. CompletedAt) { Write-Host "Completato: $($state. CompletedAt)" -ForegroundColor green } # Mostra indicatore di stato se ($state. TotalDevicesTargeted -gt 0) { $pct = if ($state. TotalDevicesUpdated - e $state. TotalDevicesTargeted) { [math]::Round(($state. TotalDevicesUpdated /$state. TotalDevicesTargeted) * 100, 1) } altro { 0 } Write-Host "" Write-Host "Avanzamento: " -NoNewline $barWidth = 40 $filled = [math]::Floor($barWidth * $pct / 100) Write-Host "[" -NoNewline Write-Host ("█" * $filled) -ForegroundColor green -NoNewline Write-Host ("░" * ($barWidth - $filled)) -ForegroundColor DarkGray -NoNewline Write-Host "] $pct%" } # Riepilogo contenitori bloccati if (Test-Path $blockedBucketsPath) { $blocked = Get-Content $blockedBucketsPath -Raw | ConvertFrom-Json | ConvertTo-Hashtable se ($blocked. Count -gt 0) { Write-Host "" Write-Host "BUCKET BLOCCATI: " -NoNewline -ForegroundColor red Write-Host "$($blocked. Conteggio) contenitori richiedono attenzione" -Primo pianoColore rosso if ($ShowBlocked) { Write-Host "" foreach ($key in $blocked. Tasti) { $info = $blocked[$key] Write-Host " $ $key" -ForegroundColor red Write-Host " Motivo: $($info. Reason)" -ForegroundColor Gray Write-Host " Dispositivo: $($info. FailedDevice)" -ForegroundColor gray Write-Host " Since: $($info. BlockedAt)" -ForegroundColor gray } } else { Write-Host " Esegui con -ShowBlocked per i dettagli" -ForegroundColor Gray } } } # Cronologia delle onde se ($ShowWaves -e $state. WaveHistory - e $state. WaveHistory.Count -gt 0) { Write-Host "" Write-Host "CRONOLOGIA DELLE ONDE" -ForegroundColor yellow Write-Host ("-" * 40) foreach ($wave in $state. WaveHistory) { Write-Host "Onda $($wave. WaveNumber): " -NoNewline -ForegroundColor Ciano Write-Host "$($wave. DeviceCount) dispositivi" -NoNewline Write-Host " - $($wave. StartedAt)" -ForegroundColor gray } } # Dashboard più recente $latestAggregation = Get-ChildItem -Path $ReportBasePath -Directory -Filter "Aggregation_*" -ErrorAction SilentlyContinue | nome Sort-Object -Decrescente | Select-Object -Primo 1 if ($latestAggregation) { $dashboard = Get-ChildItem -Path $latestAggregation.FullName -Filter "*Dashboard*.html" -ErrorAction SilentlyContinue | Select-Object -Primo 1 if ($dashboard) { Write-Host "" Write-Host "DASHBOARD PIÙ RECENTE" -Primo pianoColore giallo Write-Host $dashboard. FullName -ForegroundColor Gray if ($OpenDashboard) { Start-Process $dashboard. Fullname } } } # Log recente if ($ShowLog) { $logFile = Get-ChildItem -Path $stateDir -Filter "Orchestrator_*.log" -ErrorAction SilentlyContinue | nome Sort-Object -Decrescente | Select-Object -First 1 if ($logFile) { Write-Host "" Write-Host "LOG RECENTE" -Primo pianoColore giallo Write-Host ("-" * 40) Get-Content $logFile.FullName -Tail 20 | ForEach-Object { if ($_ -match '\[ERROR\]') { Write-Host $_ -ForegroundColor red } elseif ($_ -match '\[WARN\]') { Write-Host $_ -ForegroundColor yellow } elseif ($_ -match '\[OK\]') { Write-Host $_ -ForegroundColor green } elseif ($_ -match '\[WAVE\]') { Write-Host $_ -ForegroundColor Ciano } else { Write-Host $_ -ForegroundColor Gray } } } } Write-Host "" Write-Host ("-" * 80) -ForegroundColor DarkGray if (-not $ShowLog -or -not $ShowWaves -or -not $ShowBlocked) { Write-Host "Opzioni: -MostraLog | -ShowWaves | -ShowBlocked | -OpenDashboard | -Watch 30" -ForegroundColor DarkGray } }
# ============================================================================ N. PRINCIPALE # ============================================================================
if (-not (Test-Path $ReportBasePath)) { Write-Host "Percorso report non trovato: $ReportBasePath" -Primo pianoColore rosso uscita 1 }
if ($Watch -gt 0) { Write-Host "Stato di osservazione ogni $Watch secondi. Premere CTRL+C per interrompere". -ForegroundColor Ciano while ($true) { Mostra-Stato $Watch Start-Sleep -Seconds } } else { Mostra-Stato }