Работа с пользовательскими объектами Invoke-RestMethod - PullRequest
0 голосов
/ 06 июня 2019

Я использую Invoke-RestMethod (через PowerShell 6.2.1) для запроса предупреждений монитора Azure:

Invoke-RestMethod -Method Get -Uri $url -Authentication Bearer -Token $securetoken  | foreach { $_.value }

В настоящее время у меня есть 2 открытых оповещения ЦП в Azure:

enter image description here

При запуске командлета я вижу возвращенные пользовательские объекты:

nextLink value
-------- -----
         {@{properties=; id=/subscriptions/MySubscriptionID/providers/Microsoft.AlertsManagement/alerts/97fb8c3e-1e5b-4df5-9daa-46d8b115572f; type=Microsoft.Alert…

Но когда я пытаюсь распечатать конкретные объекты для каждого предупреждения из полезной нагрузки, единственное значение, которое я получаю, это name пользовательский объект:

targetResourceName :
targetResourceType :
alertState         :
severity           :
name               : Percentage CPU greater than 95

targetResourceName :
targetResourceType :
alertState         :
severity           :
name               : Percentage CPU greater than 95

Это ужасно, поскольку если я преобразую выходные данные обратно в json, я увижу все значения объектов для двух предупреждений:

{
  "nextLink": "",
  "value": [
    {
      "properties": {
        "essentials": {
          "severity": "Sev3",
          "signalType": "Metric",
          "alertState": "New",
          "monitorCondition": "Fired",
          "monitorService": "Platform",
          "targetResource": "/subscriptions/MySubscriptionID/resourcegroups/MyResourceGroup/providers/microsoft.compute/virtualmachines/myshobtestvm2",
          "targetResourceName": "myshobtestvm2",
          "targetResourceGroup": "MyResourceGroup",
          "targetResourceType": "virtualmachines",
          "sourceCreatedId": "MySubscriptionID_MyResourceGroup_microsoft.insights_metricAlerts_Percentage CPU greater than 95_-847848048",
          "smartGroupId": "9f422583-bbd8-4b71-a2fa-4e7651b64ada",
          "smartGroupingReason": "Similar to other alerts in the group",
          "alertRule": "/subscriptions/MySubscriptionID/resourceGroups/MyResourceGroup/providers/microsoft.insights/metricAlerts/Percentage CPU greater than 95",
          "startDateTime": "2019-06-06T11:49:31.0380889Z",
          "lastModifiedDateTime": "2019-06-06T11:49:31.0380889Z",
          "lastModifiedUserName": "System",
          "actionStatus": {
            "isSuppressed": false
          },
          "description": "{\n\"text test\":\"#alertrulename fired with #searchresultcount over threshold of #thresholdvalue.\"\n\n}"
        }
      },
      "id": "/subscriptions/MySubscriptionID/providers/Microsoft.AlertsManagement/alerts/97fb8c3e-1e5b-4df5-9daa-46d8b115572f",
      "type": "Microsoft.AlertsManagement/alerts",
      "name": "Percentage CPU greater than 95"
    },
    {
      "properties": {
        "essentials": {
          "severity": "Sev3",
          "signalType": "Metric",
          "alertState": "New",
          "monitorCondition": "Fired",
          "monitorService": "Platform",
          "targetResource": "/subscriptions/MySubscriptionID/resourcegroups/MyResourceGroup/providers/microsoft.compute/virtualmachines/myshobtestvm",
          "targetResourceName": "myshobtestvm",
          "targetResourceGroup": "MyResourceGroup",
          "targetResourceType": "virtualmachines",
          "sourceCreatedId": "MySubscriptionID_MyResourceGroup_microsoft.insights_metricAlerts_Percentage CPU greater than 95_1621321698",
          "smartGroupId": "9f422583-bbd8-4b71-a2fa-4e7651b64ada",
          "alertRule": "/subscriptions/MySubscriptionID/resourceGroups/MyResourceGroup/providers/microsoft.insights/metricAlerts/Percentage CPU greater than 95",
          "startDateTime": "2019-06-06T11:17:35.7461221Z",
          "lastModifiedDateTime": "2019-06-06T11:17:35.7461221Z",
          "lastModifiedUserName": "System",
          "actionStatus": {
            "isSuppressed": false
          },
          "description": "{\n\"text test\":\"#alertrulename fired with #searchresultcount over threshold of #thresholdvalue.\"\n\n}"
        }
      },
      "id": "/subscriptions/MySubscriptionID/providers/Microsoft.AlertsManagement/alerts/b929895f-c7c8-45c2-a6a7-1afe0048b30f",
      "type": "Microsoft.AlertsManagement/alerts",
      "name": "Percentage CPU greater than 95"
    }
  ]
}
...