question

AnirbanGoswami-8125 avatar image
0 Votes"
AnirbanGoswami-8125 asked AnirbanGoswami-8125 commented

"Register-AzAutomationScheduledRunbook" giving an error at Powers-shell script

Hi All,

I am new to power-shell and cmldt.

I hv a power-shell script(.ps1) like "Invoke-xxDevopDt" and it registered as azure Runbooks with an azure Automation Account. This Runbook scheduled to do a another work on other date . Now ,I want to register this Runbook by using " Register-AzAutomationScheduledRunbook" at below ps-script as below

 *param ( 
     [Parameter(Mandatory = $false)]
     [string]$resourceGroup='rsgrp_test',
    
     [Parameter(Mandatory = $false)]
     [string]$automationAccountName='Azureaucnt-test',
    
     [Parameter(Mandatory = $false)]
     [datetime]$startDateTime='01/05/2021 6:00:00 PM' ,
    
     [Parameter(Mandatory = $false)]
     [string]$vmResourceIds='/subscriptions/5454-7d8e-xxx-b628-yy3232/resourceGroups/TSTDEV/providers/Microsoft.Compute/virtualMachines/TSTDevVM',
    
     [Parameter(Mandatory = $false)]
     [String] $IncludedKBs='4588962',
    
     [Parameter(Mandatory = $false)]
     [datetime] $vmRestartDateTime='01/06/2021 4:00:00 PM',
    
     [Parameter(Mandatory = $false)]
     [String] $description = "Automated trigger from C# Program"
    
 )
     #do Login-AzAccount  to login azure subcription  
     ....    
     #setting data for   
     $AddMinutes = 7
    
     # creating an scheduling and registering 
     $scheduleName = "testAPP_devopsSchedule_" + "$(Get-Date $vmRestartDateTime -UFormat %Y-%m-%d_%A_%H-%M)"
     $devopsSchedule = New-AzAutomationSchedule -ResourceGroupName $resourceGroup `
                                                       -AutomationAccountName $automationAccountName `
                                                       -Name $scheduleName `
                                                       -StartTime ($vmRestartDateTime.AddMinutes($AddMinutes)) `
                                                       -Onetime -Verbose
    
     #Createing a param for registering another PS-script as runBook with automation-acnt
     $params = @{"serverList"=$vmResourceIds;"testMessage"="test";"description"="Invoking Automation from Automation Account"}
     #register 'Invoke-xxDevopDt' is like a ps-script at runBook of automation-acnt
     Register-AzAutomationScheduledRunbook –AutomationAccountName $automationAccountName `
                         –Name 'Invoke-xxDevopDt' –ScheduleName $devopsSchedule.Name –Parameters $params `
                         -ResourceGroupName $resourceGroup*


But, it gave an ERROR at "Register-AzAutomationScheduledRunbook : A positional parameter cannot be found that accepts argument 'Invoke-xxDevopDt'."

Any help

Thanks,


windows-server-powershellazure-automationazure-scheduler
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

I am trying to register by using 'Register-AzAutomationScheduledRunbook' at above script with another 'Invoke-xxDevopDt' ps-script type as Azure runbook in Azure automation account which is doing scheduling some job at another date.

0 Votes 0 ·

Which variable is the value "Invoke-AureDevopsPatchingUpdate" assigned to?

0 Votes 0 ·

Thanks @IanXue-MSFT for replay.
It is a typo mistake. I corrected it. There is no 'Invoke-AureDevopsPatchingUpdate' word at paragraph.
It corrected to 'Invoke-xxDevopDt' . It is kind a ps-script as Runbook that scheduled for do a work at future date.

Thanks,

0 Votes 0 ·

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered AnirbanGoswami-8125 commented

Hi,

I tested the cmdlet and it worked for me, so I don't think it's a powershell issue. Try opening the script file in a hex editor and check if there are any non-printing characters such as zero width space in the command Register-AzAutomationScheduledRunbook.

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks @IanXue-MSFT for replay.

I am using vs code IDE with powershell plugin for debugging above script file.
I need to check carefully any extra blank space or any others white space characters at

 '. Register-AzAutomationScheduledRunbook'

Thanks,


0 Votes 0 ·