Copie e cole este script de exemplo e modifique conforme necessário para seu ambiente:
<# . SINOPSE Mostra o status atual do orquestrador de distribuição de inicialização segura.
.DESCRIPTION Fornece visibilidade em tempo real sobre o progresso da distribuição: – Número de onda atual e dispositivos direcionados - Dispositivos atualizados versus pendentes – Buckets bloqueados que exigem atenção - Log de atividades recente – Link do painel Execute isso a qualquer momento para ver como a distribuição está progredindo.
.PARAMETER ReportBasePath Caminho para o diretório relatório/estado usado pelo orquestrador
.PARAMETER ShowLog Exibir entradas de log recentes (últimas 50 linhas)
.PARAMETER ShowBlocked Mostrar detalhes de buckets bloqueados
.PARAMETER ShowWaves Mostrar histórico de ondas com contagens de dispositivos
.PARAMETER Watch Atualizar continuamente status a cada N segundos
.PARAMETER OpenDashboard Abra o dashboard HTML mais recente no navegador
.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( [Parameter(Mandatory = $true)] [string]$ReportBasePath, [Parameter(Mandatory = $false)] [switch]$ShowLog, [Parameter(Mandatory = $false)] [switch]$ShowBlocked, [Parameter(Mandatory = $false)] [switch]$ShowWaves, [Parameter(Mandatory = $false)] [int]$Watch = 0, [Parameter(Mandatory = $false)] [switch]$OpenDashboard )
$ErrorActionPreference = "Stop" $DownloadUrl = "https://aka.ms/getsecureboot" $DownloadSubPage = "Exemplos de implantação e monitoramento"
# Note: This script has no dependencies on other scripts. # Para o conjunto de ferramentas completo, baixe de: $DownloadUrl -> $DownloadSubPage
# ============================================================================ # FUNÇÕES AUXILIARES # ============================================================================
function ConvertTo-Hashtable { param([Parameter(ValueFromPipeline = $true)]$InputObject) processo { se ($null -eq $InputObject) { retornar @{} } se ($InputObject -is [System.Collections.IDictionary]) { retornar $InputObject } se ($InputObject -is [PSCustomObject]) { $hash = @{} foreach ($prop em $InputObject.PSObject.Properties) { $hash[$prop. Nome] = ConvertTo-Hashtable $prop. Valor } retornar $hash } se ($InputObject -is [System.Collections.IEnumerable] -e $InputObject -isnot [string]) { { retornar @($InputObject | ForEach-Object { ConvertTo-Hashtable $_ }) } retornar $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 Cyan Write-Host " STATUS DE DISTRIBUIÇÃO DE INICIALIZAÇÃO SEGURA" -ForegroundColor Cyan Write-Host " $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor Gray Write-Host ("=" * 80) -ForegroundColor Cyan Write-Host "" # Verificar se a tarefa do orquestrador está em execução $task = Get-ScheduledTask -TaskName "SecureBoot-Rollout-Orchestrator" -ErrorAction SilentlyContinue se ($task) { $taskState = $task. Estado $color = if ($taskState -eq "Running") { "Green" } elseif ($taskState -eq "Ready") { "Yellow" } else { "Red" } Write-Host "Tarefa Agendada: " -NoNewline Write-Host $taskState -ForegroundColor $color } else { Write-Host "Tarefa agendada: " -NoNewline Write-Host "Não Instalado" -ForegroundColor Gray } # Estado de distribuição de carga if (-not (Test-Path $rolloutStatePath)) { Write-Host "" Write-Host "Nenhum estado de distribuição encontrado. O orquestrador pode ainda não ter começado." -ForegroundColor Yellow Write-Host "Caminho do Estado: $rolloutStatePath" -ForegroundColor Gray Retorno } $state = Get-Content $rolloutStatePath -Raw | ConvertFrom-Json | ConvertTo-Hashtable Write-Host "" Write-Host "ROLLOUT PROGRESS" -ForegroundColor Yellow Write-Host ("-" * 40) $status = $state. Status $statusColor = comutador ($status) { "Concluído" { "Verde" } "InProgress" { "Cyan" } "NotStarted" { "Gray" } padrão { "Branco" } } Write-Host "Status: " -NoNewline Write-Host $status -ForegroundColor $statusColor Write-Host "Onda Atual: $($state. CurrentWave)" Write-Host "Destino Total: $($state. TotalDevicesTargeted)" Write-Host "Total atualizado: $($state. TotalDevicesUpdated)" se ($state. StartedAt) { Write-Host "Started: $($state. StartedAt)" } se ($state. LastAggregation) { Write-Host "Último cheque: $($state. LastAggregation)" } se ($state. CompletedAt) { Write-Host "Concluído: $($state. CompletedAt)" -ForegroundColor Green } # Mostrar barra de progresso se ($state. TotalDevicesTargeted -gt 0) { $pct = se ($state. TotalDevicesUpdated -e $state. TotalDevicesTargeted) { [math]::Round(($state. TotalDevicesUpdated/$state. TotalDevicesTargeted) * 100, 1) } else { 0 } Write-Host "" Write-Host "Progresso: " -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%" } # Resumo de buckets bloqueados se ($blockedBucketsPath de caminho de teste) { $blocked = Get-Content $blockedBucketsPath -Raw | ConvertFrom-Json | ConvertTo-Hashtable se ($blocked. Contagem -gt 0) { Write-Host "" Write-Host "BUCKETS BLOQUEADOS: " -NoNewline -ForegroundColor Red Write-Host "$($blocked. Contagem) buckets precisam de atenção" -ForegroundColor Red se ($ShowBlocked) { Write-Host "" foreach ($key no $blocked. Chaves) { $info = $blocked[$key] Write-Host " ► $key" -ForegroundColor Red Write-Host " Razão: $($info. Reason)" -ForegroundColor Gray Write-Host " Dispositivo: $($info. FailedDevice)" -ForegroundColor Gray Write-Host " Desde: $($info. BlockedAt)" -ForegroundColor Gray } } else { Write-Host " Executar com -ShowBlocked para obter detalhes" -ForegroundColor Gray } } } # Histórico de ondas se ($ShowWaves -e $state. WaveHistory - e $state. WaveHistory.Count -gt 0) { Write-Host "" Write-Host "WAVE HISTORY" -ForegroundColor Yellow Write-Host ("-" * 40) foreach ($wave no $state. WaveHistory) { Write-Host "Wave $($wave. WaveNumber): " -NoNewline -ForegroundColor Cyan Write-Host "$($wave. Dispositivos DeviceCount) " -NoNewline Write-Host " – $($wave. StartedAt)" -ForegroundColor Gray } } # Última dashboard $latestAggregation = Get-ChildItem -Path $ReportBasePath -Directory -Filter "Aggregation_*" -ErrorAction SilentlyContinue | Sort-Object Nome -Decrescente | Select-Object -Primeiro 1 se ($latestAggregation) { $dashboard = Get-ChildItem -Path $latestAggregation.FullName -Filter "*Dashboard*.html" -ErrorAction SilentlyContinue | Select-Object -Primeiro 1 se ($dashboard) { Write-Host "" Write-Host "DASHBOARD MAIS RECENTE" -ForegroundColor Yellow Write-Host $dashboard. FullName -ForegroundColor Gray se ($OpenDashboard) { Start-Process $dashboard. Fullname } } } # Log recente se ($ShowLog) { $logFile = Get-ChildItem -Path $stateDir -Filter "Orchestrator_*.log" -ErrorAction SilentlyContinue | Sort-Object Nome -Decrescente | Select-Object -Primeiro 1 se ($logFile) { Write-Host "" Write-Host "LOG RECENTE" -ForegroundColor Yellow Write-Host ("-" * 40) Get-Content $logFile.FullName -Tail 20 | ForEach-Object { se ($_ -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 Cyan } else { Write-Host $_ -ForegroundColor Gray } } } } Write-Host "" Write-Host ("-" * 80) -ForegroundColor DarkGray se (-não $ShowLog -ou -não $ShowWaves -ou -não $ShowBlocked) { Write-Host "Opções: -ShowLog | -ShowWaves | -ShowBlocked | -OpenDashboard | -Assista a 30" -ForegroundColor DarkGray } }
# ============================================================================ # MAIN # ============================================================================
if (-not (Test-Path $ReportBasePath)) { Write-Host "Caminho do relatório não encontrado: $ReportBasePath" -ForegroundColor Red saída 1 }
if ($Watch -gt 0) { Write-Host "Observando status a cada $Watch segundos. Pressione Ctrl+C para parar." -ForegroundColor Cyan while ($true) { Show-Status Start-Sleep -Seconds $Watch } } else { Show-Status }