-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure_usage.ps1
35 lines (32 loc) · 1.3 KB
/
azure_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
Function Get-AzureUsage {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[datetime]$FromTime,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[datetime]$ToTime,
[Parameter()]
[ValidateNotNullOrEmpty()]
[ValidateSet('Hourly', 'Daily')]
[string]$Interval = 'Daily'
)
Write-Verbose -Message "Querying usage data [$($FromTime) - $($ToTime)]..."
$usageData = $null
do {
$params = @{
ReportedStartTime = $FromTime
ReportedEndTime = $ToTime
AggregationGranularity = $Interval
ShowDetails = $true
}
if ((Get-Variable -Name usageData -ErrorAction Ignore) -and $usageData) {
Write-Verbose -Message "Querying usage data with continuation token $($usageData.ContinuationToken)..."
$params.ContinuationToken = $usageData.ContinuationToken
}
$usageData = Get-UsageAggregates @params
$usageData.UsageAggregations | Select-Object -ExpandProperty Properties
} while ('ContinuationToken' -in $usageData.psobject.properties.name -and $usageData.ContinuationToken)
}
$usage = Get-AzureUsage -FromTime '08-30-19' -ToTime '09-30-19' -Interval Hourly -Verbose