How-to-simply...

Make REST API call with BasicAuth header from PowerShell on Windows

  • 1 $username = "user"
    $password = "pass"
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
    $headers = @{
    "Authorization" = "Basic $base64AuthInfo"
    "ContentType" = "application/json"
    }
    Invoke-RestMethod -Uri "https://example.com/api/method" -Headers $headers -Method Get
  • N You can make a REST API request with a BasicAuth header included from PowerShell on Windows using the 'Invoke-RestMethod' cmdlet.