while running azure cost management API from Azure Devops pipeline its fail
Hi,
I struggle in running one PowerShell script in Azure Pipeline. The PowerShell works fine under windows 11. but when I run the same script in the azure pipeline with “Windows-latest” its fails with stating error “the remote server returned an error: (400) Bad Request“.
script contets:
—————————
—————————————
The above code failed on the last command when trying to run “Invoke-RestMethod”
Hi, I struggle in running one PowerShell script in Azure Pipeline. The PowerShell works fine under windows 11. but when I run the same script in the azure pipeline with “Windows-latest” its fails with stating error “the remote server returned an error: (400) Bad Request”. script contets:————————— $currentDate = get-date -Format “yyyy-MM-dd” $startDateOfLastMonth = (get-date $currentDate -Day 1).AddMonths(-1) $endDateOfLastMonth=GET-DATE $startDateOfLastMonth.AddMonths(1).AddSeconds(-1) $billingPeriod = (get-date).AddMonths(-1).ToString(‘yyyyMM’) #get-date -format ‘yyyyMM’ function get-token(){ $token = (Get-AzAccessToken -ResourceUrl ‘https://management.azure.com’ ).Token $headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]” $headers.Add(“Authorization”,”Bearer $token”) return $headers } $headers = get-token $subscriptions = Get-AzSubscription $usageUri = “https://management.azure.com/subscriptions/$($subId)/providers/Microsoft.Billing/billingPeriods/$($billingPeriod)/providers/Microsoft.Consumption/usageDetails?api-version=2018-03-31&$filter=properties/usageStart ge $startDateOfLastMonth AND properties/usageEnd le $endDateOfLastMonth” Invoke-RestMethod $usageUri -Headers $headers -ContentType “application/json” -Verbose—————————————The above code failed on the last command when trying to run “Invoke-RestMethod” Read More