Get-AzureAutomationAccount returns 空集合
Get-AzureAutomationAccount returns empty collection
我似乎无法从 Azure Runbook 使用 Azure 自动化 cmdlets
访问任何内容。下面我成功获得了订阅中的所有虚拟机,但调用 Get-AzureAutomationAccount
returns 是一个空集合(我有 2 个自动化帐户)。我可以使用自动化进行的任何其他调用 cmdlets
return 为空或未找到异常。
提前感谢您的任何建议!
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]
}
}
您是通过 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:
Automation accounts, and the resources they contain, that are created with the Azure preview portal cannot be accessed in the Azure portal. If you want to manage these accounts or their resources with Windows PowerShell, you must use the Azure Resource Manager modules.
Automation accounts created with the Azure portal can be managed by either portal and either set of cmdlets. Once the account is created, it makes no difference how you create and manage resources within the account. If you are planning to continue to use the Azure portal, then you should use it instead of the Azure preview portal to create any Automation accounts.
如果这确实是问题的原因,解决方案是使用 ARM cmdlet 而不是 RDFE/ASM cmdlet 来访问您的自动化帐户和其中的任何内容。例如:
Add-AzureRmAccount -Credential $Cred
Get-AzureRmAutomationAccount
Get-AzureRmAutomationRunbook
我似乎无法从 Azure Runbook 使用 Azure 自动化 cmdlets
访问任何内容。下面我成功获得了订阅中的所有虚拟机,但调用 Get-AzureAutomationAccount
returns 是一个空集合(我有 2 个自动化帐户)。我可以使用自动化进行的任何其他调用 cmdlets
return 为空或未找到异常。
提前感谢您的任何建议!
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]
}
}
您是通过 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:
Automation accounts, and the resources they contain, that are created with the Azure preview portal cannot be accessed in the Azure portal. If you want to manage these accounts or their resources with Windows PowerShell, you must use the Azure Resource Manager modules.
Automation accounts created with the Azure portal can be managed by either portal and either set of cmdlets. Once the account is created, it makes no difference how you create and manage resources within the account. If you are planning to continue to use the Azure portal, then you should use it instead of the Azure preview portal to create any Automation accounts.
如果这确实是问题的原因,解决方案是使用 ARM cmdlet 而不是 RDFE/ASM cmdlet 来访问您的自动化帐户和其中的任何内容。例如:
Add-AzureRmAccount -Credential $Cred
Get-AzureRmAutomationAccount
Get-AzureRmAutomationRunbook