首页 > 解决方案 > Azure 自动化 - 我们能否将参数从 powershell 主运行手册传递给 python 子进程

问题描述

我面临一个我没有找到解决方案的问题。我试图从我的父母那里执行一个 python 运行手册,它在 powershell 中。

我在我的 powershell runbook 中尝试过的命令列表:

这是我的变量参数:

如果有人有解决方案,我将不胜感激!我试了一整天都没有成功。

预先感谢您的帮助

标签: azureautomationazure-functionspower-automateazure-runbook

解决方案


-Parameters 选项不适用于 Python runbooks 。您可以从另一个 Runbook 中使用 Start-AutomationRunbook 的 -Parameters 选项。

解决方法是使用内部自动化模块 Start-AutomationRunbook而不是外部 Start-AzureRmAutomation 模块。

创建一个名为Start-PythonRunbook的新 Runbook ,如下所示:

Param(
    [parameter(Mandatory=$true)] [string]$runbook,
    [string]$args
    )
Start-AutomationRunbook -Name $runbook -Parameters $args

现在,您可以使用Start-AzureRmAutomationRunbook cmdlet 启动此 Runbook:

Start-AzureRmAutomationRunbook -ResourceGroupName <RGName> 
    -AutomationAccountName <AAName> 
  -Name Start-PythonRunbook `
  -Parameters  @{ "runbook" = "<pythonrunbookname>"; "args" = "arg1 arg2 arg3 arg4 arg5 arg6" }

您可以查看此GitHub 讨论以获取更多信息。


推荐阅读