powershell之Azure PowerShell 自动化 "no default subscritpion has been designated"
我收到以下错误。事实上,我正在设置默认订阅名称。
4/27/2015 10:28:28 AM, Error: Get-AzureVM : No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription. At test:9 char:9 + + CategoryInfo : CloseError: (:) [Get-AzureVM], ApplicationException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVMCommand
这是我的代码:
workflow test
{
# Initial set up
$Cred = Get-AutomationPSCredential -Name "******"
Add-AzureAccount -Credential $Cred
Select-AzureSubscription -Default -SubscriptionName 'Beebunny'
$vmName = "MyMachineName"
Get-AzureVM -servicename $vmName
Write-output "All done."
}
如果我尝试 Select-AzureSubscription -Default 'SubscriptionName' 它会抛出一个错误,指出语法无效。
编辑:我还尝试了不带默认标志的 Select-AzureSubscription -SubscriptionName 'SubscriptionName'。
有趣的是,如果我直接从 Windows 在 AzurePS 中运行它,它运行得很好。我大约 95% 确信这是一个 Azure 错误,但想先获得第二意见。
请您参考如下方法:
您加载了哪个版本的 Azure 模块?您是否使用自动化服务提供的默认模块?另外,您是否已将任何其他模块导入到此订阅中?
尝试使用以下代码创建一个干净的 Runbook,并将凭据和订阅替换为正确的名称。您能否获得凭证并成功进行身份验证?
workflow Test-GetVM
{
$Cred = Get-AutomationPSCredential -Name 'AdAzureCred'
if(!$Cred) {
Throw "Could not find an Automation Credential Asset named. Make sure you have created one in this Automation Account."
}
$Account = Add-AzureAccount -Credential $Cred
if(!$Account) {
Throw "Could not authenticate to Azure. Make sure the user name and password are correct."
}
Select-AzureSubscription -SubscriptionName "Visual Studio Ultimate with MSDN"
Get-AzureVM
}
更新:您是否也将资源管理器模块加载到订阅中?
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。