在Azure Rule JSON中删除嵌套的pscustomobject

时间:2018-11-26 21:56:00

标签: json powershell

曾经努力删除Azure警报规则查询返回的JSON中的嵌套对象。

感谢这里的人们,我已经学习了如何在另一个内部添加PSCustomObject。在这种情况下,(如下)添加一个webhook操作

"actions": [
    {
        "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction, Microsoft.WindowsAzure.Management.Mon.Client",
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
        "sendtoserviceowners": true,
        "customEmails": [
            "email2@domain.com",
            "email1@domain.com"
        ]
    }
]
$rule.properties.actions += [PSCustomObject]@{
    '$type' = "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleWebhookAction, Microsoft.WindowsAzure.Management.Mon.Client";
    'odata.type' = "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleWebhookAction";
    serviceuri = "http://www.webhooktest.com"
}

产生的结果

"actions": [
    {
        "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleWebhookAction, Microsoft.WindowsAzure.Management.Mon.Client",
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleWebhookAction",
        "serviceUri": "http://www.webhooktest.com"
    },
    {
        "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction, Microsoft.WindowsAzure.Management.Mon.Client",
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
        "sendToServiceOwners": false,
        "customEmails": [
            "email2@domain.com",
            "email1@domain.com"
        ]
    }
]

我需要能够删除Webhook并留下电子邮件。如果可以使用+=添加它,为什么要尝试使用-=

删除它
$rule.properties.actions -= [PSCustomObject]@{
    '$type' = "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleWebhookAction, Microsoft.WindowsAzure.Management.Mon.Client";
    'odata.type' = "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleWebhookAction";
    serviceuri = "http://www.webhooktest.com"
}

导致

  

[System.Object []]中的结果不包含名为“ op_Subtraction”的方法

我也没有使用Remove()方法的运气。什么会起作用?

0 个答案:

没有答案