Setting Bearer tokens in PowerShell
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.