我正在自动创建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
答案 0 :(得分:2)
管理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
您可能错过了其中一个步骤。