0
我想按時間表運行Runbook,但如果上一個作業尚未完成,則退出(例如,如果時間表爲每2小時一個作業需要2.5小時,則接下來的作業不應該運行)。在Azure Runbook中獲取作業狀態
我試過使用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]
謝謝。我試過,但我得到了同樣的錯誤; 「Get-AzureRmAutomationJob:沒有找到自動化帳戶」 – SturmUndDrang
好了,那麼你只需檢查拼寫,這可能是訣竅?你也想要指定-ResourceGroup開關和resourcegroup開關 – 4c74356b41