<# .Synopsis Azure Page/Block Blob の 実容量を求める .Description Azure Page Blob, Block Blob の実容量のサイズを計算。 # 参考 # http://gallery.technet.microsoft.com/scriptcenter/Get-Billable-Size-of-32175802 # Get Billable Size of Windows Azure Blobs (w/Snapshots) in a Container or Account .PARAMETER Url blob url 自身のサブスクリプションにある、BLOBのUrl、または、ContainerのUrl。 あらかじめ、Add-AzureAccount, AzureRmAccount して、 Select-AzureSubscription, Select-AzureRmSubscription しておくこと。 または、SASToken付きのURL。 .PARAMETER blob Blob object 自身のサブスクリプションにある Blob object。 .Example .\Get-BlobBytes.ps1 -Url 'https://xxxxxxx.blob.core.windows.net/vhds/xxxxxxxxxxx.vhd' | ft -auto output: BlobName BlobLength BlobGB ActualBytes ActualGB -------- ---------- ------ ----------- -------- aaaaaaaaaaaaa-OSDisk.vhd 32214352384 30.00 16399651125 15.27 .Example .\Get-BlobBytes.ps1 -url 'https://xxxxxxx.blob.core.windows.net/vhds/' | ft -auto output: BlobName BlobLength BlobGB ActualBytes ActualGB -------- ---------- ------ ----------- -------- xxxxxxxxxxxxx-OSDisk.vhd 32214352384 30.00 16399651125 15.27 yyyyyyyyyyyyy-OSDisk.vhd 32214352384 30.00 14647733691 13.64 .Example .\Get-BlobBytes.ps1 -Url 'https://xxxxxxx.blob.core.windows.net/xxxxx/xxxxx?sv=xxx&si=xxxxxxxxxxxx' | ft -auto output: BlobName BlobLength BlobGB ActualBytes ActualGB -------- ---------- ------ ----------- -------- abcd 32214352384 30.00 15704441101 14.63 .Example # $storage = Get-AzureRmStorageAccount -ResoueceGroupName "ResourceGroupName" -StorageAccountName "StorageAccountName" $blob = Get-AzureStorageBlob -Context $storage.Context -Container "vhds" -Blob "vhdname" .\Get-BlobBytes.ps1 -Blob $blob | ft -auto .Example # $storage = Get-AzureRmStorageAccount -ResoueceGroupName "ResourceGroupName" -StorageAccountName "StorageAccountName" Get-AzureStorageBlob -Context $storage.Context -Container "vhds" | .\Get-BlobBytes.ps1 | ft -auto #> param( [parameter(ParameterSetName="Url")] [alias("uri")] [string] $url, [parameter(ParameterSetName="Blob", Mandatory=$true,ValueFromPipeline=$true)] [object[]] $Blob ) PROCESS{ $ErrorActionPreference = 'stop' if ( $Url ) { if ( $Url -match '^(?http(s?)\:\/\/)(?[^\/:]+)\.blob\.core\.windows\.net(?(:\d*)|)\/(?[^\/]+)(\/|)(?[^\?]+|)(?\?.+|)$' ) { if ( $matches["storage"] -and $matches["sas"] ) { $context = New-AzureStorageContext -StorageAccountName $matches["storage"] -SasToken $matches["sas"] } elseif ( $matches["storage"] ) { $s = $null try { $s = Get-AzureStorageAccount -StorageAccountName $matches["storage"] -EA 'stop' } catch [Exception] {} if ( -not $s ) { $s = Get-AzureRmStorageAccount | ? StorageAccountName -eq $matches["storage"] $s = $s | select -first 1 } $context = $s.Context } else { Write-Error "cannot get azure storage: $Url" } if ( $matches["blob"] ) { $Blob = Get-AzureStorageBlob -Context $context -Container $matches["container"] -Blob $matches["blob"] } else { $Blob = Get-AzureStorageBlob -Context $context -Container $matches["container"] } } else { Write-Error "invalid Url: $Url" } } if ( $Blob ) { $Blob | %{ $b = $_ # Base + blob name $BlobSizeInBytes = 124 + $b.Name.Length * 2 # Get size of metadata $metadataEnumerator = $b.ICloudBlob.Metadata.GetEnumerator() while ($metadataEnumerator.MoveNext()) { $BlobSizeInBytes += 3 + $metadataEnumerator.Current.Key.Length + $metadataEnumerator.Current.Value.Length } if ($b.BlobType -notmatch "PageBlob" ) { $BlobSizeInBytes += 8 $b.ICloudBlob.DownloadBlockList() | ForEach-Object { $BlobSizeInBytes += $_.Length + $_.Name.Length } } else { $b.ICloudBlob.GetPageRanges() | ForEach-Object { $BlobSizeInBytes += 12 + $_.EndOffset - $_.StartOffset } } $o = New-Object -TypeName PSObject $o | Add-Member "BlobName" $b.Name $o | Add-Member "BlobLength" $b.Length $o | Add-Member "BlobGB" ('{0:#,##0.00}' -f ($b.Length/1GB)) $o | Add-Member "ActualBytes" $BlobSizeInBytes $o | Add-Member "ActualGB" ('{0:#,##0.00}' -f ($BlobSizeInBytes/1GB)) $o } } }