I need some improvements for the array, I want to add on an Array an extra Line with custom value like the sum for the costs… The way I did, is not the best way, can someone help me?
$subs = Get-AzSubscription
$currentBillingPeriod = Get-AzBillingPeriod -name 202209 #-MaxCount 1
$startDate = $currentBillingPeriod.BillingPeriodStartDate.ToString("dd-MM-yyyy")
Write-Host "currentBillingPeriod startDate : " $startDate
$endDate = $currentBillingPeriod.BillingPeriodEndDate.ToString("dd-MM-yyyy")
Write-Host "currentBillingPeriod endDate : " $endDate
$report = @()
foreach ($sub in $subs){
$x = "" | Select 'Subscription','cost in Euro','Period'
$acSub = Set-AzContext -SubscriptionName $sub.name
$currentCost = Get-AzConsumptionUsageDetail -StartDate $startDate -EndDate $endDate | Measure-Object -Property PretaxCost -Sum
$x.Subscription = $sub.name
$x.'cost in Euro' = [math]::round($currentCost.Sum,2)
$x.'Period' = $currentBillingPeriod.name
$report += $x
Write-Host "Current Cost of Subscription :" $sub.name $currentCost.Sum
}
$report
$mailreport = $report
$sum = ($mailreport | Measure-Object 'cost in Euro' -Sum).sum
$mailreport += '-'
$mailreport += '-'
$mailreport += 'Summe in Euro'
$mailreport += $sum
$mailreport
2
Answers
I found a solution any improvements?
I think you need to make a custom ps object, where you pour in the contents from the array, as well as the extra property you need