0

我希望按计划运行运行手册,但如果最后一个作业尚未完成运行,则退出(即,如果计划是每 2 小时一次,一个作业需要 2.5 小时,那么下一个作业不应该运行)。

我尝试使用 Get-AzureAutomationJob 来获取最后的作业状态(https://azure.microsoft.com/en-gb/documentation/articles/automation-runbook-execution/#retrieving-job-status-using-windows -powershell),但我无法让它工作。我认为获得订阅等的所有序言都是必需的。

“Get-AzureAutomationJob:找不到自动化帐户。”

$ConnectionAssetName = "AzureClassicRunAsConnection"

# Get the connection
$connection = Get-AutomationConnection -Name $connectionAssetName        

# Authenticate to Azure with certificate
Write-Verbose "Get connection asset: $ConnectionAssetName" -Verbose
$Conn = Get-AutomationConnection -Name $ConnectionAssetName
if ($Conn -eq $null)
{
    throw "Could not retrieve connection asset: $ConnectionAssetName. Assure            that this asset exists in the Automation account."
}

$CertificateAssetName = $Conn.CertificateAssetName
Write-Verbose "Getting the certificate: $CertificateAssetName" -Verbose
$AzureCert = Get-AutomationCertificate -Name $CertificateAssetName
if ($AzureCert -eq $null)
{
    throw "Could not retrieve certificate asset: $CertificateAssetName.       Assure that this asset exists in the Automation account."
}

Write-Verbose "Authenticating to Azure with certificate." -Verbose
Set-AzureSubscription -SubscriptionName $Conn.SubscriptionName -      SubscriptionId $Conn.SubscriptionID -Certificate $AzureCert 
Select-AzureSubscription -SubscriptionId $Conn.SubscriptionID

$job = (Get-AzureAutomationJob –AutomationAccountName "THE NAME OF THE AUTOMATION ACCOUNT AS IT APPEARS IN THE PORTAL" –Name "JobStatusTest" | sort LastModifiedDate –desc)[0]
4

1 回答 1

0

那么,您需要为此使用 Get-AzureRMAutomation 作业。让我详细说明一下,我认为微软在 2016 年 3 月从旧的 azure 模型中删除了 Azure 自动化,现在它只存在于新模型中。所以你需要将 RM 添加到你的命令行开关

于 2016-11-02T08:31:53.233 回答