0

当我使用 powershell 创建新预算并尝试使用相同的命令设置警报时,它会设置但不显示在成本警报部分以及警报条件中未显示的金额。

下面是命令:

Set-AzConsumptionBudget -Amount $Amount -Name $BudgetName `
    -ResourceGroupName $RGName -Category Cost -StartDate $StartDate `
    -EndDate $EndDate -ContactEmail $EmailId -NotificationKey $Key `
    -NotificationThreshold 0.8 -NotificationEnabled -TimeGrain Monthly `
    -ContactGroup $ActionGroupId

下面是显示金额字段未填充的图像:

在此处输入图像描述

我可以在预算部分看到它,但在成本警报部分看不到:

在此处输入图像描述

4

1 回答 1

0

意识到:

  • 预算必须始终从每月 1 日开始
  • CMDlet 有问题。更好的是你使用 GraphAPI

这里有一些使用 Powershell 的示例

$StartofMonth = (Get-Date -Format yyyy-MM).ToString()
$EndOfBudget = (Get-Date).AddMonths(+$MonthUntilNuke) | Get-Date -UFormat "%Y-%m-%d"

$RestBody = @{
    properties = @{
        "category"      = "Cost";
        "amount"        = $budgetAmount;
        "unit"          = "EUR";
        "timeGrain"     = "Annually";
        "timePeriod"    = @{
            "startDate" = "$($StartofMonth)-01T00:00:00Z";
            "endDate"   = "$($EndOfBudget)T00:00:00Z"
        };
        "notifications" = @{
            "AlertAt95Percent"  = @{
                "enabled"       = "true";
                "operator"      = "GreaterThan";
                "threshold"     = 95;
                "thresholdType" = "Actual";
                "contactEmails" = @(
                    "$UPN",
                    "$AdditionalContact"
                )
            };
            "AlertAt100Percent" = @{
                "enabled"       = "true";
                "operator"      = "EqualTo";
                "threshold"     = 100;
                "thresholdType" = "Actual";
                "contactGroups" = @(
                    "/subscriptions/xxxx79c5/resourceGroups/xxxxnt/providers/microsoft.insights/actiongroups/DisableSubscription"
                )
            }
        }
    }
}

$ApiVersion = "api-version=2019-10-01"
$restURI = "https://management.azure.com/subscriptions/$($Subscription.Id)/providers/Microsoft.Consumption/budgets/myBudget?$ApiVersion"
于 2021-02-23T10:48:06.900 回答