Unauthorize action to run Get-AzStorageShare

Elroy Tong 0 Reputation points
2024-06-19T09:50:42.9466667+00:00

i have built a script for a resource HealthCheck, however i encountered an authorize error issue when i use the get-azStorageshare .
My current script displays the azure storage accounts and utilization, please find the error message below
the user is given owner permission to the storage account.
Please share your inputs and questions.

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,833 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sumarigo-MSFT 44,511 Reputation points Microsoft Employee
    2024-06-20T03:16:14.84+00:00

    @Elroy Tong Welcome to Microsoft Q&A Forum. Thank you for posting your query here!

    The "Authorize error" issue you are encountering when using the Get-AzStorageShare cmdlet may be due to a permissions issue. Here are a few things you can check to resolve the issue:

    Check the permissions: Make sure that the user account you are using to run the script has the necessary permissions to access the storage account and its resources. The user account should have at least "Storage Blob Data Contributor" or "Storage Blob Data Owner" role assigned to it.

    Authentication method: Make sure that you are using the correct authentication method to access the storage account. If you are using a service principal, make sure that the service principal has the necessary permissions to access the storage account.

    Storage account name: Make sure that you are using the correct storage account name in the Get-AzStorageShare cmdlet. Double-check the spelling and make sure that the storage account exists in the same subscription and region as the script.

    Storage account type: Make sure that the storage account type is supported by the Get-AzStorageShare cmdlet. The cmdlet only supports standard storage accounts, not premium storage accounts.

    Get-AzStorageShare : This article provides details information what all it can list in File share with examples, Parameters, Inputs, Output and more

    The idea is to call Get-AzStorageShare which will give you an object of type AzureStorageFileShare. This object has a property called ShareClient which is available in Azure Storage File SDK. Once you have access to this object, you can call GetStatistics method to get the share usage.

    $accountName = "your storage account name"
    $accountKey = "your storage account key"
    $shareName = "your share name"
    $ctx = New-AzStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey
    $share = Get-AzStorageShare -Name $shareName
    $client = $share.ShareClient
    # We now have access to Azure Storage SDK and we can call any method available in the SDK.
    # Get statistics of the share
    $stats = $client.GetStatistics()
    $shareUsageInBytes = $stats.Value.ShareUsageInBytes
    Write-Host $shareUsageInBytes
    
    

    **If the issue still persists, can you please share the screen shot of the error message
    **
    Additional information: Monitor Azure Files: https://learn.microsoft.com/en-us/azure/storage/files/storage-files-monitoring

    Please let us know if you have any further queries. I’m happy to assist you further.    


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

0 additional answers

Sort by: Most helpful