PowerShell筛选JSON中Active状态受影响区域脚本需求
修正后的PowerShell脚本实现
核心处理逻辑
- 读取目标Azure服务健康JSON文件并转换为PowerShell对象
- 双重筛选:先过滤事件整体状态为Active的条目,再在这些条目中提取区域状态为Active的受影响区域
- 关联输出所需的
SubscriptionId、ImpactedService等关联信息
示例脚本
# 读取JSON文件内容(替换为你的实际文件路径) $healthJsonPath = "C:\your-path\azure-service-health-data.json" $healthData = Get-Content -Path $healthJsonPath -Raw | ConvertFrom-Json # 筛选并提取符合条件的数据 $activeImpactedData = $healthData | ForEach-Object { # 仅处理事件状态为Active的条目 if ($_.Status -eq "Active") { # 提取该事件下状态为Active的受影响区域 $activeRegions = $_.ImpactedRegions | Where-Object { $_.Status -eq "Active" } # 关联输出所需字段 foreach ($region in $activeRegions) { [PSCustomObject]@{ SubscriptionId = $_.SubscriptionId ImpactedService = $_.ImpactedService EventId = $_.EventId ImpactedRegion = $region.RegionName RegionStatus = $region.Status EventStatus = $_.Status } } } } # 控制台输出结果(可按需导出为CSV) $activeImpactedData | Format-Table -AutoSize # $activeImpactedData | Export-Csv -Path "Active-Impacts.csv" -NoTypeInformation
关键说明
- 双重状态校验:同时校验事件整体和区域维度的状态,避免误判已恢复的区域
- 灵活扩展字段:可根据需求在
PSCustomObject中添加EventType、StartTime等额外字段 - 数据导出:注释部分提供了CSV导出命令,方便后续离线分析
内容的提问来源于stack exchange,提问作者Charly
相关产品推荐
相关产品推荐

