4
votes

New to Azure and Powershell. I used the following script to connect to my Azure subscription and storage account.

Import-Module "C:\Program Files (x86)\Microsoft SDKs\WindowsAzure\PowerShell\Azure\Azure.psd1"
Import-AzurePublishSettingsFile 'C:\AZURE_POWERSHELL\DETAILS.publishsettings'
Set-AzureSubscription -SubscriptionName subname -CurrentStorageAccount storagename
Select-AzureSubscription -SubscriptionName subname

I wish to query the storage account now to:

  • Count the number of containers in Blob.
  • Count the number of documents these containers.
  • Return the file storage size of all documents.
  • Return the file storage size of documents with a specified date range.

Is this possible from Azure Powershell?

Thank you.

1

1 Answers

4
votes

Get number of containers

(Get-AzureStorageContainer).Count

Get number of blobs in container

(Get-AzureStorageBlob -Container "ContainerName").Count

Not sure if you want file sizes for each individual file or an aggregate size.

Individual file sizes can be shown with Get-AzureStorageBlob -Container "ContainerName" which list a Length attribute for each blob. Length is the blob size in bytes.

Total file size can be retrieved by doing this

Get-AzureStorageBlob -Container "ContainerName" | %{ $_.Length } | measure -Sum

To get files that were last modified in a specific date range just do

Get-AzureStorageBlob -Container "ContainerName" | where { $_.LastModified -gt (Get-Date -Date "specific date") -and $_.LastModified -lt (Get-Date -Date "specific date") }