gpt4 book ai didi

azure - 在 azure 中为警报规则创建 PowerShell 脚本时出现错误

转载 作者:行者123 更新时间:2023-12-02 23:51:08 26 4
gpt4 key购买 nike

$condition1 = New-AzureRmActivityLogAlertCondition -Field 'category' -Equal 'Administrative'
$condition2 = New-AzurermActivityLogAlertCondition -Field 'resourceType' -Equal 'Microsoft.Network/NetworkSecurityGroups'
$email1 = New-AzureRmActionGroupReceiver -Name 'alertget' -EmailReceiver -EmailAddress '<emailaddress>'
$actionGrp=Set-AzureRmActionGroup -Name "withpowershell" -ResourceGroup "<rgname>" -ShortName "Palert" -Receiver $email1
Set-AzurermActivityLogAlert -Location 'Global' -Name 'alertme' -ResourceGroupName '<rgname>' -Scope '/subscriptions/<subsID>' -Action $actionGrp -Condition $condition1,$condition2

但是每次我运行此代码时都会收到如下错误:

Set-AzureRmActivityLogAlert : Cannot bind parameter 'Action'. Cannot convert the 
"Microsoft.Azure.Commands.Insights.OutputClasses.PSActionGroupResource" value of type
"Microsoft.Azure.Commands.Insights.OutputClasses.PSActionGroupResource" to type
"Microsoft.Azure.Management.Monitor.Management.Models.ActivityLogAlertActionGroup".
At line:1 char:163
+ ... ions/911df94d-12e9-4695-a90f-943a1bef518d' -Action $actionGrp -Condit ...
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-AzureRmActivityLogAlert], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.Insights.ActivityLogAlert.SetAzureRmActivityLogAlertCommand

请告诉我解决方案

最佳答案

您需要在内存中创建一个 ActionGroup 引用对象。添加此行 $actionGrp1 = New-AzureRmActionGroup -ActionGroupId $actionGrp.Id到您的脚本,然后更改 -Action $actionGrp-Action $actionGrp1在最后一行,那么它就会起作用。

完整脚本:

$condition1 = New-AzureRmActivityLogAlertCondition -Field 'category' -Equal 'Administrative'
$condition2 = New-AzurermActivityLogAlertCondition -Field 'resourceType' -Equal 'Microsoft.Network/NetworkSecurityGroups'
$email1 = New-AzureRmActionGroupReceiver -Name 'alertget' -EmailReceiver -EmailAddress '<emailaddress>'
$actionGrp=Set-AzureRmActionGroup -Name "withpowershell" -ResourceGroup "<rgname>" -ShortName "Palert" -Receiver $email1
$actionGrp1 = New-AzureRmActionGroup -ActionGroupId $actionGrp.Id
Set-AzurermActivityLogAlert -Location 'Global' -Name 'alertme' -ResourceGroupName '<rgname>' -Scope '/subscriptions/<subsID>' -Action $actionGrp1 -Condition $condition1,$condition2

enter image description here

注意:我使用新的 Az 进行测试模块,用于AzureRm模块,都是同样的逻辑。

关于azure - 在 azure 中为警报规则创建 PowerShell 脚本时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59169314/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com