使用 Powershell 5.1 Runbook。
我正在尝试测试从另一个 Runbook 发送电子邮件。使用与我在第二个 Runbook 中使用的参数相同的参数,SendEmailToDba Runbook 成功运行。我不明白为什么它提示“ResourceGroupName”参数。它是 Start-AzureAutomationRunbook 的必需参数。
$params = @{ "destEmailAddress" = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="315c5471525e5c41505f481f525e5c" rel="noreferrer noopener nofollow">[email protected]</a>"; "fromEmailAddress" = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9c4cce9cac6c4d9c8c7d087cac6c4" rel="noreferrer noopener nofollow">[email protected]</a>"; "subject" = "test Email from Runbook"; "content" = "This is a test from another runbook" }
Write-Output( $params )
$job = Start-AzureAutomationRunbook `
-Name "SendEmailToDba" `
-Parameters $params `
-AutomationAccountName "myAccount" `
-ResourceGroupName "my-automation-resourcegroup"
然后我收到以下错误:
System.Management.Automation.ParameterBindingException:找不到与参数名称“ResourceGroupName”匹配的参数。
在 System.Management.Automation.CmdletParameterBinderController.VerifyArgumentsProcessed(ParameterBindingException 原始BindingException)
在 System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection1 参数) 在 System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection
1 参数)
在 System.Management.Automation.CommandProcessor.BindCommandLineParameters()
在 System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
在 System.Management.Automation.Internal.PipelineProcessor.Start( bool 传入流)
在 System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate (对象输入)
--- 从先前抛出异常的位置开始的堆栈跟踪结束 ---
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate (对象输入)
在System.Management.Automation.PipelineOps.InvokePipeline(对象输入, bool 忽略输入,CommandParameterInternal [] [] pipelineElements,CommandBaseAst [] pipeElementAsts,CommandRedirection [] [] commandRedirections,FunctionContext funcContext)
在 System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame 框架)
在 System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame 框架)
在System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame框架)
最佳答案
由于命令不正确,出现“ResourceGroupName”
无法识别或错误给出的错误。
Start-AzureAutomationRunbook
不是有效的 PowerShell
命令。您需要使用
用于启动自动化 Runbook 的 Start-AzAutomationRunbook/Start-AzureRMAutomationRunbook
命令。
注意:
- 将 PowerShell Runbook 版本更新至
7.1/7.2
以避免出现一些问题。 - 确保在
Azure 自动化帐户 -> 模块
中安装Az
和Az.Automation
PowerShell 模块,以使用启动-AzAutomationRunbook
cmdlet。 - 引用MSDoc .
我修改了您的脚本如下:
connect-Azaccount -identity
$params = @{ "destEmailAddress" = "destmailID"; "fromEmailAddress" = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e18c84a1828e8c91808f98cf828e8c" rel="noreferrer noopener nofollow">[email protected]</a>"; "subject" = ""; "content" = "" }
$AutomationAccount = "jahnaviauto"
$Runbook = "myrunbook"
$ResourceGroup = "Jahnavi"
$RunbookParameters = @{
Name = $Runbook
AutomationAccount = $AutomationAccount
ResourceGroup = $ResourceGroup
}
Start-AzAutomationRunbook @RunbookParameters
您可以根据需要更改参数和相关信息并尝试该脚本。
输出:
关于Azure 自动化启动-AzureAutomationRunbook 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75868292/