我似乎無法從Azure Runbook訪問任何與Azure自動化cmdlets
。下面我成功地獲得了我訂閱中的所有虛擬機,但撥打Get-AzureAutomationAccount
會返回一個空集合(我擁有2個自動化帳戶)。我可以使用自動化cmdlets
的任何其他調用返回空或未找到異常。Get-AzureAutomationAccount返回空集合
在此先感謝您的任何建議!
workflow Get-AzureVMTutorial
{
#The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
$CredentialAssetName = 'AaronCred'
#Get the credential with the above name from the Automation Asset store
$Cred = Get-AutomationPSCredential -Name $CredentialAssetName
if(!$Cred) {
Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account."
}
#Connect to your Azure Account
$Account = Add-AzureAccount -Credential $Cred
if(!$Account) {
Throw "Could not authenticate to Azure using the credential asset '${CredentialAssetName}'. Make sure the user name and password are correct."
}
#TODO (optional): pick the right subscription to use. Without this line, the default subscription for your Azure Account will be used.
#Select-AzureSubscription -SubscriptionName "TODO: your Azure subscription name here"
#Get all the VMs you have in your Azure subscription
$VMs = Get-AzureVM
#Print out up to 10 of those VMs
if(!$VMs) {
Write-Output "No VMs were found in your subscription."
} else {
Write-Output $VMs[0..9]
}
# PROBLEM - No accounts are returned even though I have 2
$automationAccounts = Get-AzureAutomationAccount
#Print out up to 10 of those automation accounts
if(!$automationAccounts) {
Write-Output "No automation accounts were found in your subscription."
} else {
Write-Output $VMs[0..9]
}
}
,其實自動化帳戶只是通過portal.azure.com昨天測試這個問題產生。 –
好了,那麼您需要使用與該門戶相對應的cmdlet:Add-AzureRmAccount,Get-AzureRmAutomationAccount,Get-AzureRmAutomationRunbook等,如此答案所述。 Get-AzureAutomationAccount是一個與舊門戶相對應的cmdlet。 – Joe
然後這是正確的答案。非常感謝喬。閱讀您發送的鏈接我發現當我通過portal.azure.com創建Azure自動化帳戶時,我需要使用Azure資源管理器Cmdlet(https://msdn.microsoft.com/zh-cn/library/mt244122.aspx) 。 不幸的是,他們的主頁現在在https://azure.microsoft.com/en-us/documentation/services/automation/(自動化 - >自動化Cmdlet)指向舊文檔,這是我誤用的。 –