Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Standard disclaimer : This code is provided as a sample and is in no way warranted for production use.
- function global:get-StorageBlobGBSize
- {
- param (
- [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBlob] $blob
- )
- $blobGBSize = [math]::Truncate(($blob.Length / 1GB))
- return $blobGBSize
- }
- # authenticate to Azure and select the correct subscription if you have multiple subscriptions
- Connect-AzureRmAccount
- #Select-AzureRmSubscription -SubscriptionId 'Specify_Subscription_ID'
- #List all Storage Accounts in the selected subscription
- $storageAccountName = Get-AzureRMStorageAccount | select StorageAccountName, ResourceGroupName
- Write-Host -ForegroundColor Black -BackgroundColor Cyan "Fetching all the Storage Accounts under the above subscription and its corressponding resource group"
- Import-Module AzureRmStorageTable
- foreach($name in $storageAccountName)
- {
- Write-Host $name.StorageAccountName running under resource Group $name.ResourceGroupName
- # $saPremium = Find-AzureRmResource -ResourceNameEquals $name.StorageAccountName | Where-Object {$_.Sku.tier -eq "Premium" } -ErrorAction SilentlyContinue -WarningAction Continue
- $tableMetrics = Get-AzureStorageTableTable -resourceGroup $name.ResourceGroupName -tableName '$MetricsCapacityBlob' -storageAccountName $name.StorageAccountName -ErrorAction SilentlyContinue -WarningAction Continue
- #Get Values in the capacity table
- Get-AzureStorageTableRowAll -table $tableMetrics | select -Last '2' | ft
- $storageAccessKey = ((Get-AzureRmStorageAccountKey -ResourceGroupName $name.ResourceGroupName -Name $name.StorageAccountName)[0]).Value
- $storageContext = New-AzureStorageContext –StorageAccountName $name.StorageAccountName –StorageAccountKey $storageAccessKey
- $containers = Get-AzureStorageContainer -Context $storageContext
- $StorageAccountUsage = '' | select StorageAccountName,Allocated_GB
- foreach ($container in $containers)
- {
- If($container -ne '$web')
- {
- $blobsContainer = Get-AzureStorageBlob -Context $storageContext -Container $container.Name -ErrorAction SilentlyContinue
- foreach ($blob in $blobsContainer)
- {
- $blobSize = get-StorageBlobGBSize ($blob)
- $StorageAccountUsage.Allocated_GB = $StorageAccountUsage.Allocated_GB + $blobSize
- }
- }
- }
- write-host -BackgroundColor Yellow -ForegroundColor Black "The capacity of Storage Account:" $name.StorageAccountName "is" $StorageAccountUsage.Allocated_GB
- Write-Host ===============================================================================================
- }
Add Comment
Please, Sign In to add comment