Azure EA订阅 - 结算报告

时间:2017-01-09 05:55:53

标签: powershell azure enterprise billing

尝试通过powershell获取azure计费报告,在开始之前询问注册号和访问密钥,可以从https://ea.azure.com找到注册密钥,但是如果可以,则不会在任何地方明确提及访问密钥从存储帐户获取,然后我有超过20个存储帐户用于不同的资源,

有任何建议通过powershell检索计费EA详细信息。

1 个答案:

答案 0 :(得分:1)

我希望您通过Gordon Byers

<强>示例:

$baseurl = "https://ea.azure.com/rest/"
$enrollmentNo ="100"
$accesskey ="eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Il92ZHZieDJYRUkyb2l5N09abVpVelZGelM2TSJ9.eyJpc3MiOiJlYS5taWNyb3NvZnRhenVyZS5jb20iLCJhdWQiOiJjbGllbnQuZWEubWljcm9zb2Z0YXp1cmUuY29tIiwibmJmIjoxNDI4NDYwOTgxLCJleHAiOjE0NDQyNzIxODEsIkVucm9sbG1lbnROdW1iZXIiOiIxMDAiLCJJZCI6Ijk3OGQ5MGRjLTEyZjUtNDVmZC1hZWY2LWNiZTQ0ZDE0NmFmNiIsIlJlcG9ydFZpZXciOiJTeXN0ZW0iLCJQYXJ0bmVySWQiOiIifQ.QEHdbHmUz4TXO8Ljhn8ktnt5m7rHO0hsRrDLTvoQP4luL-8gy98CywFi2OByhfPL6UY5Vx8MYtwTQhMbzefS6Cd8hNopP74AL1ENLT-WGn42JG2mWesizIuN1QHV-obZR5rKDT57leurgEWy3LscWlwM0v5vhtk-9e5p8_9YgYqnF3rC05l1kUBQYzEIeYeMxcp8YxsqlnQNoEdCIA4UN08Py7zjr0ohCYbkm76a0-XdquqOTdSKGrnFkmwPxzjWMkuX3f2zpck_Ps8x8TVBpfvywly0QjUbN0ssmLV20zrS8FqkKSdx13uQVzM3MXCBylu5WvhTKE_ogRJdxPpfiA"
$authHeaders = @{"authorization"="bearer $accesskey";"api-version"="1.0"}

Write-Host "Summary info"
$url= $baseurl + $enrollmentNo + "/usage-reports"
$sResponse = Invoke-WebRequest $url -Headers $authHeaders
$sContent = $sResponse.Content | ConvertFrom-Json 
#$sContent.AvailableMonths

Write-Host "Detailed Month info"
#$month="2015-04"
$month=$sContent.AvailableMonths[0].Month
$url= $baseurl + $enrollmentNo + "/usage-report?month=$month&type=detail"
$mResponse = Invoke-WebRequest $url -Headers $authHeaders

#Split the response up into an array from a string
$mContent = ($mResponse.Content -split '[rn]')

#Convert from CSV to object
$mCsv = $mContent | Where-Object { [regex]::matches($_,",").count -gt 28} | ConvertFrom-Csv
#$mCsv = $mcontent[4..$($mcontent.count)] | ConvertFrom-Csv

#$mCsv | Select-Object ServiceResource, Service, Product, date, ResourceQtyConsumed, ResourceRate, ExtendedCost  | ft

$filterDay =$mCsv[-1].Date
Write-Host "Examining for single day $filterDay"
$aday = $mCsv | Where-Object {$_.date -eq $filterDay}
$aday | Select-Object  Product, date, ResourceQtyConsumed, ResourceRate, ExtendedCost | Sort-Object ExtendedCost -Descending | ft

$adayCost = [math]::round($($aday | Select-Object -ExpandProperty ExtendedCost | Measure-Object -Sum).sum,2)
Write-Host "Azure Cost for $filterDay = £$adayCost" 

$monthCost = [math]::round($($mCsv | Select-Object -ExpandProperty ExtendedCost | Measure-Object -Sum).sum,2)
Write-Host "Azure Cost for $month = £$monthCost"

注意:在那里给出的链接中也提到了API指南。这是Azure Billing API

的最佳方式之一

希望它有所帮助。