kratka
kratka

Reputation: 144

Get-AzureResource failing

I am automating the creation of an Azure web site and want to set the pricing tier. I found a few good articles (https://azure.microsoft.com/en-us/documentation/articles/powershell-azure-resource-manager/, http://www.troyhunt.com/2015/01/automating-web-hosting-creation-in.html) that pointed me to Get-AzureResource but I cannot get it to work.

I originally had AuthenticationFailed errors with the Azure 0.8 Powershell module then upgraded to 0.9.3. I now am getting two different errors depending on the parameters I supply to Get-AzureResource. I tried different ApiVersion switches, found that I'm running 2014-04-01-preview which concerns me a bit, and confirmed that my subscription supports AzureResourceManager via Get-AzureSubscriptions. What am I missing?

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

Upvotes: 0

Views: 1358

Answers (1)

theadriangreen
theadriangreen

Reputation: 2258

The normal flow for managing Azure resources would be something like:

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

It's possible that you missed one of these steps.

Upvotes: 2

Related Questions