forked from robotechredmond/Azure-PowerShell-Snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzureRM - Get Storage Usage.ps1
89 lines (61 loc) · 2.14 KB
/
AzureRM - Get Storage Usage.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
[System.Reflection.Assembly]::LoadWithPartialName("System.Web")
# Sign-in to Azure
Login-AzureRmAccount
# Select an Azure Subscription for which to report usage data
$subscriptionId =
(Get-AzureRmSubscription |
Out-GridView `
-Title "Select an Azure Subscription ..." `
-PassThru).SubscriptionId
Select-AzureRmSubscription -SubscriptionId $subscriptionId
# Get amount of in-use storage across all storage accounts
$reportedStartTime = "2016-11-11"
$reportedEndTime = "2016-11-12"
# Set path to exported CSV file
$filename = ".\usageData-${subscriptionId}-${reportedStartTime}-${reportedEndTime}.csv"
# Set usage parameters
$granularity = "Daily" # Can be Hourly or Daily
$showDetails = $true
$continuationToken = ""
$appendFile = $false
# Export storage usage to CSV
$usageData = Get-UsageAggregates `
-ReportedStartTime $reportedStartTime `
-ReportedEndTime $reportedEndTime `
-AggregationGranularity $granularity `
-ShowDetails:$showDetails
Do {
$usageData.UsageAggregations.Properties |
Where-Object `
MeterCategory -EQ "Storage" |
Select-Object `
UsageStartTime, `
UsageEndTime, `
@{n='SubscriptionId';e={$subscriptionId}}, `
MeterCategory, `
MeterId, `
MeterName, `
MeterSubCategory, `
MeterRegion, `
Unit, `
Quantity, `
@{n='Project';e={$_.InfoFields.Project}}, `
InstanceData |
Export-Csv `
-Append:$appendFile `
-NoTypeInformation:$true `
-Path $filename
if ($usageData.NextLink) {
$continuationToken = `
[System.Web.HttpUtility]::UrlDecode($usageData.NextLink.Split("=")[-1])
$usageData = Get-UsageAggregates `
-ReportedStartTime $reportedStartTime `
-ReportedEndTime $reportedEndTime `
-AggregationGranularity $granularity `
-ShowDetails:$showDetails `
-ContinuationToken $continuationToken
} else {
$continuationToken = ""
}
$appendFile = $true
} until (!$continuationToken)