如何以Azure Automation中的父母(Powershell)Runbook拨打孩子(Powershell)runbook inline?

发布于 2025-01-21 18:49:59 字数 806 浏览 0 评论 0 原文

为了创建一些可重复使用的powershell代码,我正在尝试获取儿童运行手册的内联援引。我对Powershell和Azure自动化是相对较新的。

到目前为止,我迄今为止尝试的所有尝试从父级工作簿到子runbook失败的所有尝试都没有以下错误

:被识别为CMDLET,功能,脚本文件或可执行程序的名称。检查名称的拼写,或者如果包括路径,请验证该路径是否正确,然后重试

。这两本运行簿都位于同一自动化帐户下。

为了清楚起见,我试图将其归结为最简单的形式。这是儿童runbook 的内容,名为 rnbk_test_child

Write-Output "Hello, this is the child runbook."

parent runbook 也有一行代码,看起来像这样:

./rnbk_test_child.ps1

我在创建和测试父跑书之前首次出版了Child Runbook。我主要从此文章

In an attempt to create some reusable powershell code I am trying to get the inline invocation of a child runbook to work. I am relatively new to PowerShell and to Azure Automation.

All the attempts I made so far to make an inline call from a parent workbook to a child runbook fail with the following error:

The term './<name_of_child_runbook>.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Both runbooks are PowerShell (version 7.1). Both runbooks reside under the same Automation account.

For sake of clarity, I tried to bring it down to its simplest form. Here is the content of the child runbook, named rnbk_test_child.

Write-Output "Hello, this is the child runbook."

The parent runbook also has one single line of code and looks like this:

./rnbk_test_child.ps1

I first published the child runbook before creating and testing the parent runbook. I mainly worked from the information in this article.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

听闻余生 2025-01-28 18:49:59

您可以使用AZ CMDLET az.automation Module调用儿童runbook

$automationAccountName = '<InsertHere>'
$runbookName = '<InsertHere>'
$automationAccountResourceGroup = '<InsertHere>'

$startAutomationRunBookSplat = @{
        AutomationAccountName = $automationAccountName 
        Name                  = $runbookName
        ResourceGroupName     = $automationAccountResourceGroup 
        Parameters            = $ParametersHashtable
    }
    
    Start-AzAutomationRunbook @startAutomationRunBookSplat -verbose

有关用法的文档: https://learn.microsoft.com/en-us/powershell/module/az.automation/start-azautomationrunbook?view = azps-7.4.4.0

You can call the child runbook using the Az cmdlet Start-AzAutomationRunbook from the Az.Automation module.

$automationAccountName = '<InsertHere>'
$runbookName = '<InsertHere>'
$automationAccountResourceGroup = '<InsertHere>'

$startAutomationRunBookSplat = @{
        AutomationAccountName = $automationAccountName 
        Name                  = $runbookName
        ResourceGroupName     = $automationAccountResourceGroup 
        Parameters            = $ParametersHashtable
    }
    
    Start-AzAutomationRunbook @startAutomationRunBookSplat -verbose

Docs on the usage here: https://learn.microsoft.com/en-us/powershell/module/az.automation/start-azautomationrunbook?view=azps-7.4.0

何时共饮酒 2025-01-28 18:49:59

我不确定您是否已经弄清楚了,但据我所知,您在父级运行中需要做的就是将孩子runbook称为inline powershell函数,例如

runbktestchild -parameter1 "value"

如果运行书,我不认为它会起作用名称中有强调:S

Im not sure if you have already figured this out but as far as I'm aware all you need to do in the parent runbook is call the child runbook as if it was a inline powershell function

e.g

runbktestchild -parameter1 "value"

I dont think it will work if the runbook name has underscores in it :S

讽刺将军 2025-01-28 18:49:59

不幸的是,在7.1或7.2中执行子脚本。 父级启动另一本Runbook

要从 %20使用%20.%5cchild%2drunbook.ps1%20IS%​​20NOT%20秒“ rel =“ nofollow noreferrer”> https://learn.microsoft.com/en-us/azure/azure/automation/automation-automation-automation-child-runbooks#: 〜:text =执行%20子%20个分数%20乘%20。%5cchild%2drunbook.ps1%20is%20NOT%20supported

Unfortunately, Executing child scripts using .\child-runbook.ps1 isn't supported in 7.1 or 7.2 :(. The workarround provided by MS is to Use Start-AutomationRunbook (internal cmdlet) or Start-AzAutomationRunbook (from Az.Automation module) to start another runbook from parent runbook.

Referencess: https://learn.microsoft.com/en-us/azure/automation/automation-child-runbooks#:~:text=Executing%20child%20scripts%20using%20.%5Cchild%2Drunbook.ps1%20is%20not%20supported

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文