-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-azureconsumptiondetails.ps1
37 lines (35 loc) · 1.24 KB
/
get-azureconsumptiondetails.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
<#
.SYNOPSIS
Get-Azureconsumptiondetails.ps1 - Create a report of the Azure consumption details
.DESCRIPTION
Script to prepare a report
.NOTES
Written By: Maciej Poborca
Website: https://maciejpoborca.pl
Change Log
V1.00, 15/02/2022 - Initial version - Consumption details
#>
if ( ! $(Get-AzContext) )
{
# Login to Azure Teenant
Connect-AzAccount
}
<# Part of the code responisble for subscription listing#>
$UsageDetailsTable = @()
Write-Output "$(Get-Date -format HH:mm:ss) | Getting list of the subscription"
$Subscriptions = Get-AzSubscription
$today = Get-Date
foreach ($subscription in $Subscriptions) {
$UsageDetails = Get-AzConsumptionUsageDetail -StartDate $today.AddMonths(-1) -enddate $today
$UsageDetailsTable += $UsageDetails
}
if ( $PSVersionTable.os -like "*azure*" )
{
$reportfilename = $(Get-Date -format 'yyyy-MM-dd-HHmmss') + "-UsageDetailsReport.csv"
$reportfile = $( $(Get-CloudDrive).MountPoint + '\' + $ReportFileName )
$UsageDetailsTable | ConvertTo-Csv -NoTypeInformation -Delimiter ";" | Out-File $reportfile
}
else{
$reportfilename = $(Get-Date -format 'yyyy-MM-dd-HHmmss') + "-UsageDetailsReport.csv"
$UsageDetailsTable | ConvertTo-Csv -NoTypeInformation -Delimiter ";" | Out-File .\$reportfilename
}