繁体   English   中英

使用 powershell 在 Azure 中创建自动化操作组

[英]Create Automation Action Group in Azure using powershell

我想使用此命令 Set-AzActionGroup 来操作标准自动化 Runbook 重新启动 VM,但周围似乎没有任何示例。 要在 Set-AzActionGroup 中执行此操作,我需要引用 VM、自动化帐户以及一些称为服务 uri 和 webhook 资源 ID(我认为是指运行手册)的东西。 有没有人有一个完整的例子? 我有一个 azure 自动化帐户,但需要一个 webhook。

只需尝试下面的 PowerShell 来创建一个带有重启 VM AutomationRunbookReceiver 的操作组:

$automationAccountResourceGroup = ""
$automationAccountName = ""
$webhookName = "Webhook20210316" 
$receiverEmail = ""
$actionGroupName = ""

#create automationRunbookReceivers
$webhook = New-AzAutomationWebhook -Name $webhookName -IsEnabled $true -ExpiryTime "10/2/2030" -RunbookName "RestartAzureVmInResponseToVmAlertGlobalRunbook" -ResourceGroup $automationAccountResourceGroup -AutomationAccountName $automationAccountName -Force
$serviceURI = $webhook.WebhookURI
$automationAccountID = (Get-AzResource -ResourceGroup $automationAccountResourceGroup -name $automationAccountName).ResourceId
$WebhookResourceID  = $automationAccountID + "/webhooks/" + $webhook.name
$AutomationRunbookReceiver = New-AzActionGroupReceiver -Name 'restartVM' -RunbookName 'Restart VM'  -AutomationAccountId $automationAccountID.ToLower() -IsGlobalRunbook -AutomationRunbookServiceUri $serviceURI -WebhookResourceId $WebhookResourceID 

#create email receivers
$EmailReceiver = New-AzActionGroupReceiver -Name $receiverEmail -EmailReceiver -EmailAddress $receiverEmail

Set-AzActionGroup -ResourceGroupName $automationAccountResourceGroup -Name $actionGroupName -ShortName $actionGroupName -Receiver $EmailReceiver,$AutomationRunbookReceiver

结果: 在此处输入图像描述 在此处输入图像描述

我还根据一些规则在我这边对其进行了测试,并且它可以作为例外工作:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM