我希望按计划运行Runbook,但如果最后一个作业尚未完成运行,则退出(即如果计划是每2小时一次,则作业需要2.5小时,则下一个作业不应运行)。
我尝试使用Get-AzureAutomationJob来获取上一个作业状态(Query Projection
),但我无法让它工作。我认为所有获得订阅的序言都是必需的。
“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]
答案 0 :(得分:0)
那么,您需要使用Get-AzureRMAutomation作业。让我详细说明一下,我认为在2016年3月,Microsoft从OLD azure模型中删除了Azure Automation,现在它只出现在新的模型中。所以你需要在命令行记录中添加RM