Forum Discussion

santopat's avatar
santopat
Copper Contributor
Jun 04, 2024

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:

---------------------------

        $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
        Invoke-RestMethod $usageUri -Headers $headers -ContentType "application/json" -Verbose

---------------------------------------

The above code failed on the last command when trying to run "Invoke-RestMethod" 

  • Have you tried posting this in an Azure DevOps or even Azure PowerShell forum? They might have more specific ideas.

    Outside of that, what error are you getting?
    • santopat's avatar
      santopat
      Copper Contributor

      flanakin 

       

      i was checking Azure devops only, but I have not found in drop down list.

       

      Thanks for your reply let me try to search devops forum. 

Resources