Search code examples
powershell-4.0azure-automationazure-runbook

Register-AzAutomationScheduledRunbook giving an error at Powers-shell script


I am new to power-shell and cmldt.

I registered a power-shell script(.ps1) name like "Invoke-xxDevopDt" as azure RunBooks that associated with an azure Automation Account.This RunBooks scheduled to run at another data for do some work. Below is my power-shell script(.ps1) which i used to register "Invoke-xxDevopDt" (RunBook) by using 'Register-AzAutomationScheduledRunbook' 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, above ps-script gave an ERROR as "Register-AzAutomationScheduledRunbook : A positional parameter cannot be found that accepts argument 'Invoke-xxDevopDt'."

Pls help

Thanks,


Solution

  • Add an answer to close this issue.

    At our side, we can successfully register it. And as per op's comment, the issue is due to white space, and now it can work.