{"id":761,"date":"2023-07-21T11:10:33","date_gmt":"2023-07-21T10:10:33","guid":{"rendered":"https:\/\/www.server1.dk\/?p=761"},"modified":"2023-07-21T11:18:18","modified_gmt":"2023-07-21T10:18:18","slug":"get-azure-cost-for-subscription-including-marketplace-expenses","status":"publish","type":"post","link":"https:\/\/www.server1.dk\/?p=761","title":{"rendered":"Get Azure cost for subscription including marketplace expenses with PowerShell"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This will get last month consumption for a subscription including the money spend on marketplace.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$subscriptioname = \"CHANGETHIS\"\n$roundDecimals = 2\n$lastMonthBilling = (Get-Date).AddMonths(-1).ToString('yyyyMM')\n\n# Set context to subscription\nSet-azcontext -SubscriptionName $subscriptioname\n\n# Get billing period\n$BillingPeriod = Get-AzBillingPeriod -Name $lastMonthBilling\n$startDate = $BillingPeriod.BillingPeriodStartDate.ToString(\"dd-MM-yyyy\")\n$endDate = $BillingPeriod.BillingPeriodEndDate.ToString(\"dd-MM-yyyy\")\n\n# Collect cost data\n$currentCost = Get-AzConsumptionUsageDetail -StartDate $startDate -EndDate $endDate \n$currentCost += Get-AzConsumptionMarketplace -StartDate $startDate -EndDate $endDate\n\n# Write output to screen\nWrite-Host \"Current Cost of Subscription\" (Get-AzContext).Subscription.Name \":\" ([math]::Round(($currentCost | Measure-Object -Property PretaxCost -Sum).sum,$roundDecimals))\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This will get last month consumption for a subscription including the money spend on marketplace.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[72,136,139,137,138,10],"class_list":["post-761","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-azure","tag-billing","tag-consumption","tag-cost","tag-marketplace","tag-powershell"],"_links":{"self":[{"href":"https:\/\/www.server1.dk\/index.php?rest_route=\/wp\/v2\/posts\/761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.server1.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.server1.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.server1.dk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.server1.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=761"}],"version-history":[{"count":4,"href":"https:\/\/www.server1.dk\/index.php?rest_route=\/wp\/v2\/posts\/761\/revisions"}],"predecessor-version":[{"id":765,"href":"https:\/\/www.server1.dk\/index.php?rest_route=\/wp\/v2\/posts\/761\/revisions\/765"}],"wp:attachment":[{"href":"https:\/\/www.server1.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.server1.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.server1.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}