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

Anirban Goswami 256 Reputation points
2021-01-04T14:52:04.813+00:00

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,

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,124 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,160 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,971 Reputation points Microsoft Vendor
    2021-01-08T07:16:11.707+00:00

    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.


0 additional answers

Sort by: Most helpful