You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 03:51:34