Azure File Share Used Space via PowerShell

Category: azure scripting and command line tools

Question

olegarr on Mon, 11 May 2020 00:45:46


Hello:

I wonder if there is a way to get Azure File Share Used Space via PowerShell. 

Can someone help, please?

Looks like I can use Get-AzRmStorageShare and QuotaGiB (do not see this option with AzStorageShare module), but struggle to get Used space...

Thank you!

Replies

BhargaviAnnadevara-MSFT on Mon, 11 May 2020 05:17:08


Hello olegarr,

Seems like there is no straightforward way of getting the Usage of the File share using the Get-AzRmStorageShare cmdlet.

However, you can use the Get-AzMetric cmdlet to fetch the same as follows:

(Get-AzMetric -ResourceId "<resourceID>" -MetricName "FileCapacity" -AggregationType "Average").Data

You should get a response in the following format (in bytes):

TimeStamp : 5/11/2020 3:36:00 AM
Average   : 5368709941
Minimum   :
Maximum   :
Total     :
Count     :

Hope this helps!

olegarr on Wed, 13 May 2020 14:40:53


@BhargaviAnnadevara-MSFT,

Thanks a lot for your help!

I tried to run the command 

(Get-AzMetric -ResourceId "/subscriptions/XXXXX-XXXX/resourceGroups/XYZ/providers/Microsoft.Storage/storageAccounts/StorageAcctName/fileServices/default/shares/FileShareName" -MetricName "FileCapacity" -AggregationType "Average").Data

and got the following error:

Get-AzMetric : Exception type: 
ErrorResponseException, Message: Microsoft.Azure.Mana
gement.Monitor.Models.ErrorResponseException: 
Operation returned an invalid status code 
'BadRequest'
   at Microsoft.Azure.Management.Monitor.MetricsOpera
tions.<ListWithHttpMessagesAsync>d__5.MoveNext()

Is it fixable? 

Thanks a lot!


BhargaviAnnadevara-MSFT on Wed, 13 May 2020 15:43:22


Hello olegarr,

You almost got it!

Please have the ResourceId in the following format:

/subscriptions/{subscription-id}/resourceGroups/{resourcegroup-name}/providers/Microsoft.Storage/storageAccounts/{storageaccount-name}/fileServices/default

The rest should work then. Please try and let me know in case of issues.

olegarr on Wed, 13 May 2020 16:29:32


@BhargaviAnnadevara-MSFT,

Yes, it worked.  

Thank you very much for your help!


Oleg Aronov


BhargaviAnnadevara-MSFT on Wed, 13 May 2020 16:30:48


Awesome, glad I could help! :)