azure - 如何使用 PowerShell 获取 azure 订阅的当前成本
问题描述
我正在尝试使用 PowerShell 获取我的 azure 订阅当前成本。
期望的输出:
例如:
货币 = 英镑
当前成本 = 370.74
Get-AzConsumptionUsageDetail -BillingPeriodName 202105
但这并没有给我想要的输出。
解决方案
以下查询将为您提供上述月份的费用。例如:五月的成本
Get-AzConsumptionUsageDetail -BillingPeriodName 202105
但是,如果您的订阅不是从 5 月 1 日开始的,那么在这种情况下,上述查询会给您错误的费用。例如:您的结算周期是从 5 月 10 日到 6 月 9 日
要了解您的确切计费周期的成本,您需要首先获取当前计费周期,然后根据计费周期开始/结束日期获取成本。
$currentBillingPeriod = Get-AzBillingPeriod -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
$currentCost = Get-AzConsumptionUsageDetail -StartDate $startDate -EndDate $endDate | Measure-Object -Property PretaxCost -Sum
Write-Host "Current Cost of Subscription : " $currentCost.Sum
推荐阅读
- react-native - React Native - 是否可以查看是否正在上传重复的图像?
- flash - 有没有办法可以从死网站恢复闪存文件的地址?
- amazon-web-services - 如何在多个实例中运行 etcd?
- python - Python(Pandas) - 我应该在这里使用哪种正则表达式语法?
- dataframe - 在 excel python -Data Cleansing 中插入行
- reactjs - 反应;根据 im 所在的选项卡从数组中渲染组件
- java - 如何在android中的类aspectJ中跟踪接口内的所有函数或特定函数
- tensorflow - 在 keras 模型中使用自定义矩阵,该矩阵不是层权重的一部分,但类似于混淆矩阵,但可训练,将用于损失计算
- woocommerce - 以编程方式从 Woocommerce 中的销售价格中排除用户角色
- java - Keycloak 15 中的 ClassCastException