如何使用Powershell commandlet获取Automation Runbook现有Webhook URL
通过PowerShell获取Azure Automation Runbook的Webhook URL
前置要求
- 提前安装Azure Az.Automation PowerShell模块,若未安装可执行命令:
Install-Module -Name Az.Automation -Scope CurrentUser -Force - 执行查询前先登录Azure账号:
Connect-AzAccount,如果使用中国区Azure,额外添加参数-Environment AzureChinaCloud即可
完整查询命令
Azure官方提供的Get-AzAutomationWebhook命令默认不会返回Webhook的完整URI(安全限制),需要额外添加-WithWebhookURI参数才能获取到对应的URL。
查询指定自动化账户下所有Webhook的URL
# 替换为你自己的资源组和自动化账户名称 $resourceGroupName = "替换为你的资源组名称" $automationAccountName = "替换为你的自动化账户名称" # 获取所有Webhook及对应URL Get-AzAutomationWebhook -ResourceGroupName $resourceGroupName ` -AutomationAccountName $automationAccountName ` -WithWebhookURI | Select-Object Name, RunbookName, WebhookURI, ExpiryTime, IsEnabled
查询指定Runbook关联的Webhook URL
如果只需要查某一个Runbook对应的Webhook,在上面的命令中添加-RunbookName参数即可:
# 替换为目标Runbook名称 $runbookName = "替换为你的Runbook名称" Get-AzAutomationWebhook -ResourceGroupName $resourceGroupName ` -AutomationAccountName $automationAccountName ` -RunbookName $runbookName ` -WithWebhookURI | Select-Object Name, WebhookURI, ExpiryTime
参考截图

注意事项
- 只有拥有
Automation Contributor及以上权限的账号,才能调用-WithWebhookURI参数获取到完整的Webhook URL - 已过期、已禁用的Webhook也能查询到URI,但无法正常触发Runbook
- 不要随意泄露Webhook URL,任何拥有该URL的用户都可以直接触发对应的Runbook
内容的提问来源于stack exchange,提问作者Amruta
相关产品推荐
相关产品推荐

