Azure / Azure/azure-powershell

Issue with running Get-AZStorageUsage in Azure Stack

Open
#16,595 3 comments 0 reactions 1 assignee Claimed by @bganapa View on GitHub
Azure Stack bug customer-reported question Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 14h
Merged PRs (30d)
54

Description

### Description

https://github.com/Azure/azure-powershell/blob/main/src/Storage/Storage.Management/help/Get-AzStorageUsage.md
running the command in Azure Stack is throwing below error
Get-AzStorageUsage -Location $Location -debug
Get-AzStorageUsage: Operation returned an invalid status code 'NotFound'

comparing the URI for both AZ and AzureRM shows that Region is being used in AZ commands, even if it used in the command
AZ Module
Absolute Uri:
https://management.Region.FQDN/subscriptions/SUBID/providers/Microsoft.Storage/locations/**Region**/usages?api-version=2019-06-01

AzureRM Module
Absolute Uri:
https://management.Region.FQDN/subscriptions/SUBID/providers/Microsoft.Storage/usages?api-version=2017-10-01

### Issue script & Debug output

```PowerShell
DEBUG: Sought all Az modules and got latest version 1.10.0
DEBUG: 3:07:41 PM - GetAzureStorageUsageCommand begin processing with ParameterSet '__AllParameterSets'.
DEBUG: 3:07:41 PM - using account id
DEBUG: [Common.Authentication]: Authenticating using Account: , environment: 'AzureStackUser', tenant:
DEBUG: 3:07:41 PM - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:
Scopes:'https://management...//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:''
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.//.default ] ParentRequestId:
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.//.default ] ParentRequestId: ExpiresOn: 2021-12-07T13:21:08.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '', UserId: ''
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management./subscriptions//providers/Microsoft.Storage/locations/region/usages?api-version=2019-06-01

Headers:
x-ms-client-request-id : ed6b4a28-ae33-4b87-b0b2-f92db46e6831
Accept-Language : en-US

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
NotFound

Headers:
Cache-Control : no-cache
Pragma : no-cache
Server : Microsoft-HTTPAPI/2.0

Date : Tue, 07 Dec 2021 13:07:43 GMT

Body:

Get-AzStorageUsage: Operation returned an invalid status code 'NotFound'
DEBUG: AzureQoSEvent: CommandName - Get-AzStorageUsage; IsSuccess - False; Duration - 00:00:02.2467126; Exception - Operation returned an invalid status code 'NotFound';
DEBUG: Finish sending metric.
DEBUG: 3:07:44 PM - GetAzureStorageUsageCommand end processing.
```

### Environment data

```PowerShell
Name Value
---- -----
PSVersion 7.1.4
PSEdition Core
GitCommitId 7.1.4
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```

### Module versions

```PowerShell
Script 2.6.2 Az.Storage
```

### Error output

```PowerShell
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use `Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.

HistoryId: 17

RequestId : ea69eb8f-1c51-42b6-98e9-508d05630dbe
Message : Operation returned an invalid status code 'NotFound'
ServerMessage :
ServerResponse : {NotFound}
RequestMessage : {GET https://management.Region.FQDN/subscriptions/SUBID/providers/Microsoft.Storage/locations/Region/usages?api-version=2019-06-01}
InvocationInfo : {Get-AzStorageUsage}
Line : Get-AzStorageUsage -Location Region -debug
Position : At line:1 char:1
+ Get-AzStorageUsage -Location Region -debug
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StackTrace : at Microsoft.Azure.Management.Storage.UsagesOperations.ListByLocationWithHttpMessagesAsync(String location, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.Management.Storage.UsagesOperationsExtensions.ListByLocationAsync(IUsagesOperations operations, String location, CancellationToken cancellationToken)
at Microsoft.Azure.Management.Storage.UsagesOperationsExtensions.ListByLocation(IUsagesOperations operations, String location)
at Microsoft.Azure.Commands.Management.Storage.StorageAccount.GetAzureStorageUsageCommand.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
HistoryId : 17

HistoryId: 15

RequestId : de3ddf8e-c12b-4702-8fee-ee89b6fe33ce
Message : Operation returned an invalid status code 'NotFound'
ServerMessage :
ServerResponse : {NotFound}
RequestMessage : {GET https://management.Region.FQDN/subscriptions/SUBID/providers/Microsoft.Storage/locations/Region/usages?api-version=2019-06-01}
InvocationInfo : {Get-AzStorageUsage}
Line : ($storage = Get-AzStorageUsage -Location $region `

Position : At line:2 char:13
+ ($storage = Get-AzStorageUsage -Location $region `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StackTrace : at Microsoft.Azure.Management.Storage.UsagesOperations.ListByLocationWithHttpMessagesAsync(String location, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.Management.Storage.UsagesOperationsExtensions.ListByLocationAsync(IUsagesOperations operations, String location, CancellationToken cancellationToken)
at Microsoft.Azure.Management.Storage.UsagesOperationsExtensions.ListByLocation(IUsagesOperations operations, String location)
at Microsoft.Azure.Commands.Management.Storage.StorageAccount.GetAzureStorageUsageCommand.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
HistoryId : 15

HistoryId: 9

Message : Response status code does not indicate success: 404 (Not Found).
StackTrace : at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
Exception : Microsoft.PowerShell.Commands.HttpResponseException
InvocationInfo : {Invoke-RestMethod}
Line : $result = Invoke-RestMethod -Method Get -Uri $url -Headers $headers
Position : At line:1 char:11
+ $result = Invoke-RestMethod -Method Get -Uri $url -Headers $headers
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 9

The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.