0

When i create a new budget using powershell and try to set alert using the same command, it sets but not displaying in cost alerts section and also the amount not seen in alert conditions.

Below is the command:

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

Below is the image which shows the amount field is not populating:

enter image description here

I can see it in budget section but not in cost alert section:

enter image description here

Victor Silva
  • 723
  • 4
  • 17
Priya.D
  • 111
  • 9

1 Answers1

0

Be aware:

  • A Budget must always start at the 1st of a Month
  • CMDlets are buggy. Better you are using the GraphAPI

Here some examples to use 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"
Gill-Bates
  • 559
  • 8
  • 22