【问题标题】:How to create automation schedule for Azure Automation Runbook from PowerShell to be run on Hybrid Worker?如何从 PowerShell 创建 Azure Automation Runbook 的自动化计划以在 Hybrid Worker 上运行?
【发布时间】:2020-10-23 10:32:52
【问题描述】:

我想从 PowerShell 为 Azure Automation Runbook 创建自动化计划。我不希望它默认在 Azure 上运行,而是在 Hybrid Worker 上运行,它存在于我的 Hybrid worker groups 中。 所以我有这个命令:

Import-AzureRmAutomationRunbook -Name $runbookName `
            -Path $scriptPath `
            -ResourceGroupName $automationResourceGroupName `
            -AutomationAccountName $automationAccountName  `
            -Type PowerShellWorkflow
    
Publish-AzureRmAutomationRunbook -Name $runbookName `
            -AutomationAccountName $automationAccountName  `
            -ResourceGroupName $automationResourceGroupName

New-AzureRmAutomationSchedule -Name $runbookName ` 
            -AutomationAccountName $automationAccountName `
            -StartTime $StartTime `
            -ExpiryTime $EndTime `
            -DayInterval 1 `
            -ResourceGroupName $automationResourceGroupName

可以从 Azure 门户手动完成:

但我需要从 PowerShell 完成。我在 MS 文档上找不到它。

【问题讨论】:

    标签: azure powershell azure-automation azure-runbook


    【解决方案1】:

    如果您使用AzureRm 模块,只需使用Start-AzureRmAutomationRunbook,将-RunOn 参数指定为Hybrid Worker group 的名称。

    Start-AzureRmAutomationRunbook –AutomationAccountName "MyAutomationAccount" –Name "Test-Runbook" -RunOn "MyHybridGroup"
    

    参考(它使用新的Az 命令)-https://docs.microsoft.com/en-us/azure/automation/automation-hrw-run-runbooks#start-a-runbook-on-a-hybrid-runbook-worker

    更新:

    要安排运行手册,您可以使用Register-AzureRmAutomationScheduledRunbook,指定-RunOn 参数。

    Register-AzureRmAutomationScheduledRunbook -AutomationAccountName "Contoso17" -Name "Runbk01" -ScheduleName "Sched01" -ResourceGroupName "ResourceGroup01" -RunOn "MyHybridGroup"
    

    【讨论】:

    • 谢谢,但是可以从 PowerShell 中调度而不是运行一次吗?
    • 我会测试一下
    猜你喜欢
    • 2020-07-24
    • 2022-11-11
    • 1970-01-01
    • 2021-07-17
    • 1970-01-01
    • 1970-01-01
    • 2019-05-05
    • 1970-01-01
    • 2015-11-03
    相关资源
    最近更新 更多