如何查看 Az.Automations 下运行的 Runbook 的名称?

问题描述 投票:0回答:1

我想发送一条通知,以在 Azure 自动化下的 Runbook 中发送有关 PowerShell Runbook 结果与 Web 请求不一致的通知。

由于我想在所有 Runbook 下应用它,所以我想在消息中使用 Runbook 名称,以便我可以看到通知来自哪个 Runbook,是否有一种方法可以提取我的代码正在使用的 Runbook 名称?

我试过了

$runbookName = $MyInvocation.BoundParameters['Name'] 

但我没有成功。

azure azure-powershell azure-automation
1个回答
0
投票

使用

$MyInvocation.MyCommand.Name
变量获取当前 Runbook 的名称。

$runbookName = $MyInvocation.MyCommand.Name

要在我的 Runbook 中发送有关 PowerShell Runbook 结果与 Web 请求不一致的通知:

您可以使用

Invoke-WebRequest
PowerShell 命令与
Post
方法调用以及以下脚本。

$runbookName = $MyInvocation.MyCommand.Name
$webhookURL = "https://discord.com/" //Modify URL as per your requirement.
$message = "runbook is completed"
$reqbody = @{                                          
   content = $message
} | ConvertTo-Json
Invoke-WebRequest -Uri $webhookURL -Method Post -Body $reqbody -ContentType "application/json"

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.