【问题标题】:Get-AzureResource failing获取 AzureResource 失败
【发布时间】:2015-06-26 06:09:32
【问题描述】:

我正在自动创建 Azure 网站并希望设置定价层。我找到了几篇很好的文章(https://azure.microsoft.com/en-us/documentation/articles/powershell-azure-resource-manager/http://www.troyhunt.com/2015/01/automating-web-hosting-creation-in.html),它们将我指向 Get-AzureResource,但我无法让它工作。

我最初在 Azure 0.8 Powershell 模块中遇到 AuthenticationFailed 错误,然后升级到 0.9.3。我现在收到两个不同的错误,具体取决于我提供给 Get-AzureResource 的参数。我尝试了不同的 ApiVersion 开关,发现我正在运行 2014-04-01-preview,这让我有点担心,并通过 Get-AzureSubscriptions 确认我的订阅支持 AzureResourceManager。我错过了什么?

PS > Switch-AzureMode AzureResourceManager
WARNING: The Switch-AzureMode cmdlet is deprecated and will be removed in a future release.

$DebugPreference="Continue"
PS > Get-AzureResource -OutputObjectFormat New
DEBUG: 3:21:09 PM - GetAzureResourceCmdlet begin processing with ParameterSet 'Lists the resources based on the
specified scope.'.
DEBUG: 3:21:09 PM - using account id '###'...
Get-AzureResource : One or more errors occurred.
At line:1 char:1
+ Get-AzureResource -OutputObjectFormat New
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-AzureResource], AggregateException
    + FullyQualifiedErrorId : System.AggregateException,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementatio
   n.GetAzureResourceCmdlet



PS > Get-AzureResource -Name NNNNNNN -ResourceGroupName Default-Web-EastUS -ResourceType Microsoft.Web/sites -ApiVersion 2015-05-01 -OutputObjectFormat New
DEBUG: 3:31:55 PM - GetAzureResourceCmdlet begin processing with ParameterSet 'Lists the resources based on thespecified scope.'.
DEBUG: 3:31:55 PM - using account id '#####'...
Get-AzureResource : {
  "Error": {
    "Code": "AuthenticationFailed",
    "Message": "Authentication failed. The 'Authorization' header is not present or provided in an invalid format.",
    "Target": null,
    "Details": null
  }
}
At line:1 char:1
+ Get-AzureResource -Name NNNNNNN -ResourceGroupName Default-Web-EastUS -Res ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureResource], ErrorResponseMessageException
    + FullyQualifiedErrorId : AuthenticationFailed,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Get
   AzureResourceCmdlet

【问题讨论】:

    标签: powershell azure


    【解决方案1】:

    管理 Azure 资源的正常流程类似于:

    Switch-AzureMode -Name AzureResourceManager
    Add-AzureAccount # windows pops up to enter Microsoft account credentials
    Select-AzureSubscription -SubscriptionId '<sub-id>' # switch to the correct subscription
    Get-AzureResource -Name <site-name> -ResourceGroupName <rg-name> -ResourceType Microsoft.Web/sites
    

    您可能错过了其中一个步骤。

    【讨论】:

    • 谢谢。我删除了(Get-AzureSubscription | Remove-AzureSubscription)并重新添加了订阅和帐户详细信息,然后使用您提到的步骤成功。我曾一次或多次完成这些步骤,但显然不是以正确的顺序和正确的身份验证。我进来了!
    猜你喜欢
    • 2019-07-23
    • 2021-11-17
    • 2012-08-08
    • 2022-06-14
    • 1970-01-01
    • 2020-10-25
    • 2021-07-09
    • 2019-11-19
    • 1970-01-01
    相关资源
    最近更新 更多