I am using powershell to call VSTS API to query some json data for my build packages. I have no issues using Invoke-RestMethod to access the API but for the systems having power-shell 2.0 this cmdlet is not available and we are not authorized to install any higher version of powershell, hence I am using $WebRequest = [System.Net.WebRequest]. Is there any way I can pass my VSTS PAT(personal access token) to authenticate the web request?
0
votes
1 Answers
1
votes
The same basic process will work -- you base 64 encode your PAT, then add an Authorization header.
Something along these lines, for example:
$WebRequest = new-object System.Net.HttpWebRequest
$webrequest.Headers = new-object System.Net.WebHeaderCollection
$WebRequest.Headers.Add('Authorization', 'Basic [your base64 encoded PAT]')