Get-AzureAutomationAccount返回空集合

时间:2016-02-21 01:15:35

标签: azure azure-powershell azure-automation

我似乎无法使用Azure自动化cmdlets从azure Runbook访问任何内容。下面我成功获取了订阅中的所有虚拟机,但是对Get-AzureAutomationAccount的调用返回一个空集合(我有2个自动化帐户)。我可以使用自动化cmdlets进行的任何其他调用返回空的或未找到的异常。

提前感谢任何建议!

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]
}
}

1 个答案:

答案 0 :(得分:0)

您是通过ARM /新(以前预览版)Azure门户(portal.azure.com)还是通过RDFE / ASM /旧Azure门户(manage.windowsazure.com)创建自动化帐户?如果是前者,则无法通过RDFE / ASM /旧Azure门户访问自动化帐户,包括通过Get-AzureAutomationAccount cmdlet。来自https://azure.microsoft.com/en-us/documentation/articles/automation-configuring/#automation-accounts

  

无法在Azure门户中访问使用Azure预览门户创建的自动化帐户及其包含的资源。如果要使用Windows PowerShell管理这些帐户或其资源,则必须使用Azure资源管理器模块。

     

使用Azure门户创建的自动化帐户可以由门户网站和任一组cmdlet管理。创建帐户后,您在帐户中创建和管理资源的方式没有区别。如果您计划继续使用Azure门户,则应使用它而不是Azure预览门户来创建任何自动化帐户。

如果这确实是问题的原因,那么解决方案是使用ARM cmdlet而不是RDFE / ASM cmdlet来访问自动化帐户及其中的任何内容。例如:

Add-AzureRmAccount -Credential $Cred Get-AzureRmAutomationAccount Get-AzureRmAutomationRunbook

相关问题