0

我是 power-shell 和 cmldt 的新手。

我将诸如“Invoke-xxDevopDt”之类的 power-shell 脚本 (.ps1) 名称注册为与 azure Automation Account 关联的 azure RunBooks。这个 RunBooks 计划在另一个数据上运行以执行一些工作。下面是我用来注册“Invoke-xxDevopDt”(RunBook)的power-shell脚本(.ps1),如下所示使用“Register-AzAutomationScheduledRunbook”

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

但是,上面的 ps-script 给出了一个错误为“ Register-AzAutomationScheduledRunbook:找不到接受参数 'Invoke-xxDevopDt' 的位置参数。”

请帮忙

谢谢,

4

1 回答 1

1

添加答案以关闭此问题。

在我们这边,我们可以成功注册它。根据操作的评论,问题是由于空白,现在它可以工作了。

于 2021-02-01T02:33:34.913 回答