M Rothwell
M Rothwell

Reputation: 57

Azure Automation Start-AzureAutomationRunbook error

Using Powershell 5.1 runbook.

I'm trying to test sending an email from another runbook. The SendEmailToDba runbook runs successfully given the same parameters as I'm using in this second runbook. I cant figure out why it is complaining about the "ResourceGroupName" parameter. It is a required parameter of Start-AzureAutomationRunbook.

$params = @{ "destEmailAddress" = "[email protected]"; "fromEmailAddress" = "[email protected]"; "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"

Then I get the following error:

System.Management.Automation.ParameterBindingException: A parameter cannot be found that matches parameter name 'ResourceGroupName'. at System.Management.Automation.CmdletParameterBinderController.VerifyArgumentsProcessed(ParameterBindingException originalBindingException) at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection1 arguments) at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection1 arguments) at System.Management.Automation.CommandProcessor.BindCommandLineParameters() at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues) at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream) at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input) at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext) at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Upvotes: 0

Views: 1031

Answers (1)

Jahnavi
Jahnavi

Reputation: 8018

The error "ResourceGroupName" doesn't not recognized or wrongly given is coming because of the incorrect command.

Start-AzureAutomationRunbook is not a valid PowerShell command. You need to use
Start-AzAutomationRunbook / Start-AzureRMAutomationRunbook commands to start the automation runbooks.

Note:

  1. Update the PowerShell runbook version to 7.1 / 7.2 to avoid few concerns.
  2. Make sure to have the Az & Az.Automation PowerShell module installed in the Azure Automation account -> Modules to use the Start-AzAutomationRunbook cmdlet.
  3. Refer MSDoc.

I modified your script as below:

connect-Azaccount -identity

$params = @{ "destEmailAddress" = "destmailID"; "fromEmailAddress" = "[email protected]"; "subject" = ""; "content" = "" }

$AutomationAccount = "jahnaviauto"
$Runbook = "myrunbook"
$ResourceGroup = "Jahnavi"
$RunbookParameters = @{
Name = $Runbook
AutomationAccount = $AutomationAccount
ResourceGroup = $ResourceGroup
}
Start-AzAutomationRunbook @RunbookParameters

You can change the parameters and the relevant information as per the requirements and try the script.

Output:

enter image description here

Upvotes: 1

Related Questions