0

我似乎无法cmdlets从 azure Runbook 访问 Azure 自动化的任何内容。下面我成功获取了订阅中的所有虚拟机,但调用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]
}
}
4

1 回答 1

0

您是通过 ARM/新(以前的预览版)Azure 门户 (portal.azure.com) 还是通过 RDFE/ASM/旧 Azure 门户 (manage.windowsazure.com) 创建自动化帐户?如果是前者,自动化帐户将无法通过 RDFE/ASM/旧 Azure 门户访问,包括通过Get-AzureAutomationAccountcmdlet。来自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

于 2016-02-21T03:59:22.677 回答