このサンプル スクリプトをコピーして貼り付け、環境に合わせて必要に応じて変更します。
<# .SYNOPSIS セキュア ブート ロールアウト オーケストレーターの現在の状態を示します。
.DESCRIPTION ロールアウトの進行状況をリアルタイムで可視化します: - 対象となる現在のウェーブ番号とデバイス - デバイスの更新と保留中 - 注意が必要なブロックされたバケット - 最近のアクティビティ ログ - ダッシュボード リンク ロールアウトの進行状況を確認するには、いつでもこれを実行します。
.PARAMETER ReportBasePath オーケストレーターによって使用されるレポート/状態ディレクトリへのパス
.PARAMETER ShowLog 最近のログ エントリを表示する (最後の 50 行)
.PARAMETER ShowBlocked ブロックされたバケットの詳細を表示する
.PARAMETER ShowWaves デバイス数でウェーブ履歴を表示する
.PARAMETER Watch N 秒ごとに状態を継続的に更新する
.PARAMETER OpenDashboard ブラウザーで最新の HTML ダッシュボードを開く
.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 = "デプロイと監視のサンプル"
# Note: This script has no dependencies on other scripts. # 完全なツールセットの場合は、 からダウンロード: $DownloadUrl -> $DownloadSubPage
# ============================================================================ # ヘルパー関数 # ============================================================================
function ConvertTo-Hashtable { param([Parameter(ValueFromPipeline = $true)]$InputObject) process { if ($null -eq $InputObject) { return @{} } if ($InputObject -is [System.Collections.IDictionary]) { return $InputObject } if ($InputObject -is [PSCustomObject]) { $hash = @{} foreach ($InputObject.PSObject.Properties の$prop) { $hash[$prop。[名前] = ConvertTo-Hashtable $prop。値 } return $hash } if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string]) { return @($InputObject | ForEach-Object { ConvertTo-Hashtable $_ }) } return $InputObject } }
function Show-Status { $stateDir = Join-Path $ReportBasePath "RolloutState" $rolloutStatePath = "RolloutState.json"Join-Path $stateDir $blockedBucketsPath = "BlockedBuckets.json" Join-Path $stateDir Clear-Host "" を Write-Host する Write-Host ("=" * 80) -ForegroundColor シアン Write-Host "セキュア ブート ロールアウトの状態" -ForegroundColor シアン Write-Host " $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor Gray Write-Host ("=" * 80) -ForegroundColor シアン "" を Write-Host する # オーケストレーター タスクが実行されているかどうかを確認します $task = Get-ScheduledTask -TaskName "SecureBoot-Rollout-Orchestrator" -ErrorAction SilentlyContinue if ($task) { $taskState = $task。状態 $color = if ($taskState -eq "Running") { "Green" } elseif ($taskState -eq "Ready") { "Yellow" } else { "Red" } Write-Host "スケジュールされたタスク: " -NoNewline Write-Host $taskState -ForegroundColor $color } それ以外の { "スケジュールされたタスク: " -NoNewline を Write-Host します Write-Host "インストールされていません" -ForegroundColor Gray } # ロールアウトの状態を読み込みます if (-not (Test-Path $rolloutStatePath)) { "" を Write-Host する Write-Host "ロールアウト状態が見つかりません。 オーケストレーターはまだ開始されていない可能性があります。-ForegroundColor Yellow Write-Host "State path: $rolloutStatePath" -ForegroundColor Gray return } $state = Get-Content $rolloutStatePath -Raw |ConvertFrom-Json |ConvertTo-Hashtable "" を Write-Host する Write-Host "ロールアウトの進行状況" -ForegroundColor Yellow Write-Host ("-" * 40) $status = $state。状態 $statusColor = スイッチ ($status) { "Completed" { "Green" } "InProgress" { "シアン" } "NotStarted" { "Gray" } default { "White" } } "Status: " -NoNewline を Write-Host します Write-Host $status -ForegroundColor $statusColor Write-Host "Current Wave: $($state.CurrentWave)" Write-Host "Total Targeted: $($state.TotalDevicesTargeted)" Write-Host "合計更新: $($state。TotalDevicesUpdated)" if ($state。StartedAt) { Write-Host "Started: $($state.StartedAt)" } if ($state。LastAggregation) { Write-Host "最終確認: $($state。LastAggregation)" } if ($state。CompletedAt) { Write-Host "Completed: $($state.CompletedAt)" -ForegroundColor Green } # 進行状況バーを表示します if ($state。TotalDevicesTargeted -gt 0) { $pct = if ($state。TotalDevicesUpdated -and $state。TotalDevicesTargeted) { [math]::Round(($state.TotalDevicesUpdated/$state。TotalDevicesTargeted) * 100, 1) } else { 0 } "" を Write-Host する "Progress: " -NoNewline を Write-Host します $barWidth = 40 $filled = [math]::Floor($barWidth * $pct / 100) "[" -NoNewline を Write-Host します Write-Host ("█" * $filled) -ForegroundColor Green -NoNewline Write-Host ("░" * ($barWidth - $filled)) -ForegroundColor DarkGray -NoNewline Write-Host "] $pct%" } # ブロックされたバケットの概要 if (Test-Path $blockedBucketsPath) { $blocked = Get-Content $blockedBucketsPath -Raw |ConvertFrom-Json |ConvertTo-Hashtable if ($blocked。Count -gt 0) { "" を Write-Host する "BLOCKED BUCKETS: " -NoNewline -ForegroundColor Red を Write-Host します "$($blocked) を Write-Host します。カウント) バケットには注意が必要です" -ForegroundColor Red if ($ShowBlocked) { "" を Write-Host する foreach ($blocked の$key。キー) { $info = $blocked[$key] Write-Host " ► $key" -ForegroundColor Red Write-Host " 理由: $($info。理由)" -ForegroundColor Gray Write-Host " デバイス: $($info。FailedDevice)" -ForegroundColor Gray Write-Host " 以降: $($info。BlockedAt)" -ForegroundColor Gray } } else { Write-Host "詳細については -ShowBlocked で実行する" -ForegroundColor Gray } } } # ウェーブ履歴 if ($ShowWaves -and $state。WaveHistory -and $state。WaveHistory.Count -gt 0) { "" を Write-Host する Write-Host "WAVE HISTORY" -ForegroundColor Yellow Write-Host ("-" * 40) foreach ($state の$wave。WaveHistory) { Write-Host "Wave $($wave.WaveNumber): " -NoNewline -ForegroundColor シアン "$($wave) を Write-Host します。DeviceCount) デバイス" -NoNewline Write-Host " - $($wave。StartedAt)" -ForegroundColor Gray } } # 最新のダッシュボード $latestAggregation = Get-ChildItem -Path $ReportBasePath -Directory -Filter "Aggregation_*" -ErrorAction SilentlyContinue | Sort-Object 名 -降順 | Select-Object -First 1 if ($latestAggregation) { $dashboard = Get-ChildItem -Path $latestAggregation.FullName -Filter "*Dashboard*.html" -ErrorAction SilentlyContinue | Select-Object -First 1 if ($dashboard) { "" を Write-Host する Write-Host "LATEST DASHBOARD" -ForegroundColor Yellow Write-Host $dashboard。FullName -ForegroundColor Gray if ($OpenDashboard) { Start-Process $dashboard。FullName } } } # 最近のログ if ($ShowLog) { $logFile = Get-ChildItem -Path $stateDir -Filter "Orchestrator_*.log" -ErrorAction SilentlyContinue | Sort-Object 名 -降順 | Select-Object -First 1 if ($logFile) { "" を Write-Host する Write-Host "RECENT LOG" -ForegroundColor Yellow 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 シアン } else { Write-Host $_ -ForegroundColor Gray } } } } "" を Write-Host する Write-Host ("-" * 80) -ForegroundColor DarkGray (-not $ShowLog -or -not $ShowWaves -or -not $ShowBlocked) { Write-Host "オプション: -ShowLog |-ShowWaves |-ShowBlocked |-OpenDashboard |-Watch 30" -ForegroundColor DarkGray } }
# ============================================================================ # MAIN # ============================================================================
if (-not (Test-Path $ReportBasePath)) { Write-Host "レポート パスが見つかりません: $ReportBasePath" -ForegroundColor Red 終了 1 }
if ($Watch -gt 0) { Write-Host "$Watch 秒ごとに状態を監視しています。 Ctrl + C キーを押して停止します。-ForegroundColor シアン while ($true) { Show-Status Start-Sleep -Seconds $Watch } } else { Show-Status }