Setting Bearer tokens in PowerShell

PR Code - Christopher Pateman
1 min readJul 8, 2019

--

This is a quick post to put out how to set a Bearer Token using PowerShell for Invoke-RestMethod and Invoke-WebRequest as it was something I could not find a clear explaining post.

This is simply set in the headers of the request as below, where ‘$bearer_token’ is the token’s variable. I have put it in the ‘$headers’ variable, which is then used in the Invoke-RestMethod.

$headers = @{Authorization = "Bearer $bearer_token"} $response = Invoke-RestMethod -ContentType "$contentType" -Uri $url -Method $method -Headers $headers -UseBasicParsing

A Digital Technical Lead, constantly learning and sharing the knowledge journey. View more posts

Originally published at http://prcode.co.uk on July 8, 2019.

--

--

PR Code - Christopher Pateman
PR Code - Christopher Pateman

Written by PR Code - Christopher Pateman

I’m a Azure DevOps Engineer with a wide knowledge of the digital landscape. I enjoy sharing hard to find fixes and solutions for the wider community to use.

No responses yet