I need a Powershell script to get the Azure File Storage Total and Free usage in percentage.
Loading
I need a Powershell script to get the Azure File Storage Total and Free usage in percentage.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tasadduq BurneyPosted Aug 17, 2023, 8:08 AM
Viknaraj ManogararajahPosted Aug 14, 2023, 10:12 AM
Received the below error
Get-AzStorageUsage : A parameter cannot be found that matches parameter name 'IncludeStatistics'.
At line:1 char:89
+ ... ints.File + "default" | Get-AzStorageUsage -IncludeStatistics | Where ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-AzStorageUsage], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Azure.Commands.Management.Storage.StorageAccount.GetAzureStorageUsageCommand
Saravanan GanesanPosted Aug 4, 2023, 8:26 PM
# Connect to Azure
Connect-AzAccount
# Replace and with your actual resource group and storage account names""
$resourceGroupName = "
$storageAccountName = "
# Get the storage account
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
# Get the total storage capacity
$totalCapacity = $storageAccount.PrimaryEndpoints.File + "default" | Get-AzStorageUsage -IncludeStatistics | Where-Object { $_.Name -eq "FileCapacity" } | Select-Object -ExpandProperty Maximum
# Get the used storage capacity
$usedCapacity = $storageAccount.PrimaryEndpoints.File + "default" | Get-AzStorageUsage -IncludeStatistics | Where-Object { $_.Name -eq "FileCapacity" } | Select-Object -ExpandProperty CurrentValue
# Calculate the free capacity and percentage
$freeCapacity = $totalCapacity - $usedCapacity
$freePercentage = ($freeCapacity / $totalCapacity) * 100
$usedPercentage = 100 - $freePercentage
# Output the results
Write-Output "Total Storage Capacity: $totalCapacity bytes"
Write-Output "Used Storage Capacity: $usedCapacity bytes"
Write-Output "Free Storage Capacity: $freeCapacity bytes"
Write-Output "Used Storage Percentage: $usedPercentage%"
Write-Output "Free Storage Percentage: $freePercentage%"
Replace
andwith your actual resource group and storage account names. The script connects to your Azure account, retrieves the total and used storage capacities for the Azure File Storage, and calculates the free and used percentages. The results are then displayed in the console.Viknaraj ManogararajahPosted Jul 24, 2023, 4:51 PM
Now I'm getting "Get-AzMetric: Cannot bind parameter TimeGrain. Cannot convert value PT1H to type System.TimeSpan. Error: String PT1H was not recognized as a valid TimeSpan."
Viknaraj ManogararajahPosted Jul 24, 2023, 4:28 PM
Hi Naimish,
I'm getting the output as 0. Do I need to add anything?
Viknaraj ManogararajahPosted Jul 19, 2023, 12:08 PM
Thank you, Naimish. I appreciate your active response! It works for me.
Naimish MakwanaPosted Jul 19, 2023, 3:58 AM
Try below:
Thanks