is there a way to use powershell to get the size of an Azure File share?
I can use the Get-AzStorageShare to pull the etag, quota, tier, etc. but I can't seem to find where to get the "usage".
I can see it in the portal so it must come from somewhere...
CodePudding user response:
As of version 7.5 of Azure PowerShell, there is no Cmdlet in Az.Storage
module which would give you this information directly.
However, there is a workaround.
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