Skip to content

Instantly share code, notes, and snippets.

@rithala
Last active November 6, 2023 09:06
Show Gist options
  • Save rithala/050a16dd31a13e6d7e3c335358fcfade to your computer and use it in GitHub Desktop.
Save rithala/050a16dd31a13e6d7e3c335358fcfade to your computer and use it in GitHub Desktop.
PowerShell HTTP Request with Basic Auth
$user = 'user'
$pass = 'pass'
$uri = '<url>'
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue;
Accept = 'application/json'
}
Invoke-WebRequest -Uri $uri -Headers $Headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment