PowerShell Script: Get a Refresh Token to Authenticate to Orchestrator

by Simon Sparks · 9 February 2026

https://learn.microsoft.com/en-us/dotnet/framework/install/how-to-determine-which-versions-are-installed

[System.String]$strUsername = "service-account-name";
[System.String]$strHostFQDN = "orchestrator.cloudbuildtools.com";

[System.String]$strAccessTokenUri = "https://$strHostFQDN/csp/gateway/am/api/login?access_token";

[System.Collections.Hashtable]$objHashtable = @{'username' = $strUsername; 'password' = $password };

[System.Management.Automation.PSObject]$objPSObjectRequest = New-Object -TypeName PSObject -Property $objHashtable;

[System.String]$strJson = ConvertTo-Json -InputObject $objPSObjectRequest -Compress;

[System.Management.Automation.PSObject]$objPSObjectReturn = Invoke-RestMethod $strAccessTokenUri -Method Post -ContentType "application/json" -Body $strJson -SkipCertificateCheck -SkipHeaderValidation;

[System.String]$strRefreshToken = $objPSObjectReturn.refresh_token

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like