@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.