我似乎无法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]
}
}