我正在尝试查询Azure Cost Management,以查询两个不同日期的使用情况,每个日期用于两个不同的资源组。我正在尝试查询的值为:
1.当月总用量
1.上个月的总使用量(相对于当前日期),因此如果今天是5号,它将查询直到上个月5号的成本。
我的API总是返回空值。起初,我以为这可能只是因为今天是04/01(新的一个月的开始)......但无论我如何调整时间框架,结果似乎都没有改变。如何使用Invoke-AzCostManagementQuery执行这样的自定义查询?
$prev_month_same_day = (Get-Date).AddMonths(-1).AddDays(-1)
$first_of_prev_month = [DateTime]::ParseExact(($prev_month_same_day | Get-Date -Format "MM/01/yyyy"), 'MM/dd/yyyy', $null)
$scope_managed_rg = "/subscriptions/" + $subscription_id + "/resourceGroups/" + $db_managed_rg
$scope_unmanaged_rg = "/subscriptions/" + $subscription_id + "/resourceGroups/" + $db_unmanaged_rg
$rg1_currMonthRaw = Invoke-AzCostManagementQuery -Type "Usage" -scope $scope_managed_rg -timeframe "MonthToDate"
$rg2_currMonthRaw = Invoke-AzCostManagementQuery -Type "Usage" -scope $scope_unmanaged_rg -timeframe "MonthToDate"
$rg1_prevMonthRaw = Invoke-AzCostManagementQuery -Type "Usage" -scope $scope_managed_rg -TimePeriodFrom $first_of_prev_month -TimePeriodTo $prev_month_same_day -Timeframe "Custom"
$rg2_prevMonthRaw = Invoke-AzCostManagementQuery -Type "Usage" -scope $scope_unmanaged_rg -TimePeriodFrom $first_of_prev_month -TimePeriodTo $prev_month_same_day -Timeframe "Custom"
1条答案
按热度按时间dy2hfwbg1#
尝试以下操作: