Guest User

Untitled

a guest
Jan 22nd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. ## Standard disclaimer : This code is provided as a sample and is in no way warranted for production use.
  2.  
  3. function global:get-StorageBlobGBSize
  4. {
  5. param (
  6. [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBlob] $blob
  7. )
  8.  
  9. $blobGBSize = [math]::Truncate(($blob.Length / 1GB))
  10.  
  11. return $blobGBSize
  12.  
  13. }
  14.  
  15.  
  16. # authenticate to Azure and select the correct subscription if you have multiple subscriptions
  17. Connect-AzureRmAccount
  18.  
  19.  
  20. #Select-AzureRmSubscription -SubscriptionId 'Specify_Subscription_ID'
  21.  
  22.  
  23. #List all Storage Accounts in the selected subscription
  24.  
  25. $storageAccountName = Get-AzureRMStorageAccount | select StorageAccountName, ResourceGroupName
  26.  
  27. Write-Host -ForegroundColor Black -BackgroundColor Cyan "Fetching all the Storage Accounts under the above subscription and its corressponding resource group"
  28.  
  29. Import-Module AzureRmStorageTable
  30.  
  31. foreach($name in $storageAccountName)
  32. {
  33. Write-Host $name.StorageAccountName running under resource Group $name.ResourceGroupName
  34.  
  35. # $saPremium = Find-AzureRmResource -ResourceNameEquals $name.StorageAccountName | Where-Object {$_.Sku.tier -eq "Premium" } -ErrorAction SilentlyContinue -WarningAction Continue
  36.  
  37.  
  38.  
  39. $tableMetrics = Get-AzureStorageTableTable -resourceGroup $name.ResourceGroupName -tableName '$MetricsCapacityBlob' -storageAccountName $name.StorageAccountName -ErrorAction SilentlyContinue -WarningAction Continue
  40.  
  41.  
  42. #Get Values in the capacity table
  43.  
  44. Get-AzureStorageTableRowAll -table $tableMetrics | select -Last '2' | ft
  45.  
  46. $storageAccessKey = ((Get-AzureRmStorageAccountKey -ResourceGroupName $name.ResourceGroupName -Name $name.StorageAccountName)[0]).Value
  47.  
  48. $storageContext = New-AzureStorageContext –StorageAccountName $name.StorageAccountName –StorageAccountKey $storageAccessKey
  49.  
  50. $containers = Get-AzureStorageContainer -Context $storageContext
  51.  
  52. $StorageAccountUsage = '' | select StorageAccountName,Allocated_GB
  53.  
  54. foreach ($container in $containers)
  55. {
  56. If($container -ne '$web')
  57. {
  58. $blobsContainer = Get-AzureStorageBlob -Context $storageContext -Container $container.Name -ErrorAction SilentlyContinue
  59.  
  60. foreach ($blob in $blobsContainer)
  61. {
  62. $blobSize = get-StorageBlobGBSize ($blob)
  63.  
  64. $StorageAccountUsage.Allocated_GB = $StorageAccountUsage.Allocated_GB + $blobSize
  65. }
  66. }
  67. }
  68.  
  69. write-host -BackgroundColor Yellow -ForegroundColor Black "The capacity of Storage Account:" $name.StorageAccountName "is" $StorageAccountUsage.Allocated_GB
  70.  
  71. Write-Host ===============================================================================================
  72.  
  73. }
Add Comment
Please, Sign In to add comment