Azure PowerShell自动化“;没有指定默认的认购人;

Azure PowerShell自动化“;没有指定默认的认购人;,powershell,azure,azure-automation,Powershell,Azure,Azure Automation,我得到以下错误。事实上,我正在设置默认订阅名称 2015年4月27日上午10:28:28,错误:Get AzureVM:无默认订阅 已指定。使用Select AzureSubscription-默认值 设置默认订阅。测试时:9字符:9 + +CategoryInfo:CloseError:(:)[Get AzureVM],ApplicationException +FullyQualifiedErrorId:Microsoft.WindowsAzure.Commands.ServiceMana

我得到以下错误。事实上,我正在设置默认订阅名称

2015年4月27日上午10:28:28,错误:Get AzureVM:无默认订阅 已指定。使用Select AzureSubscription-默认值 设置默认订阅。测试时:9字符: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."
}
如果我尝试选择AzureSubscription-默认的“SubscriptionName”,它会抛出一个错误,表示语法无效

编辑:我还尝试了选择AzureSubscription-SubscriptionName'SubscriptionName',但没有默认标志


有趣的是,如果我在AzurePS中直接从Windows运行它,它运行得很好。我大约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
}

更新:您是否也将资源管理器模块加载到订阅中

我也遇到了同样的问题,解决方案是执行Add AzureAccount,执行请求的登录过程,完成后一切正常。

您是否尝试过不使用
-Default
(仅使用
-SubscriptionName'name'
)?我很想说“这应该是一条注释”,但代码不合适。你能添加你知道的案例,减少回答中间人问题的次数吗?嗨,Elizabeth,我试着在工作簿中运行你的脚本,但每次都会抛出“无法对Azure进行身份验证”。通过在测试窗格中打印凭据的用户名/密码,再次检查凭据,这是正确的。还有什么其他想法会导致这个错误吗?您是否遵循了本文中的所有步骤:确保正确设置了您正在使用的凭据?如果您正在管理ARM资源,还应该了解一下。如何在powershell脚本中做到这一点?您不能在那里弹出“添加azureaccount”框。我正在尝试为TFS构建设置此选项。请尝试使用PowerShell ISE。