Powershell 获取AzureResource失败

Powershell 获取AzureResource失败,powershell,azure,Powershell,Azure,我正在自动创建Azure网站,并希望设置定价层。我发现了几篇好文章(,)指出我需要获得AzureResource,但我无法让它发挥作用 我最初在Azure 0.8 Powershell模块中出现AuthenticationFailed错误,然后升级到0.9.3。我现在得到两个不同的错误,这取决于我为获取AzureResource提供的参数。我尝试了不同的ApiVersion开关,发现我正在运行2014-04-01-preview,这让我有点担心,并通过Get-AzureSubscriptions

我正在自动创建Azure网站,并希望设置定价层。我发现了几篇好文章(,)指出我需要获得AzureResource,但我无法让它发挥作用

我最初在Azure 0.8 Powershell模块中出现AuthenticationFailed错误,然后升级到0.9.3。我现在得到两个不同的错误,这取决于我为获取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

管理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
切换AzureMode-名称AzureResourceManager
添加AzureAccount#弹出窗口以输入Microsoft帐户凭据
选择AzureSubscription-SubscriptionId“”#切换到正确的订阅
获取AzureResource-Name-ResourceGroupName-ResourceType Microsoft.Web/sites
您可能错过了其中一个步骤。

谢谢。我删除了(获取AzureSubscription |删除AzureSubscription)并重新添加了订阅和帐户详细信息,然后使用您提到的步骤成功地完成了。我在某一点上完成了这些步骤,但显然没有按照正确的顺序使用正确的身份验证。我加入了!