Skip to content

Instantly share code, notes, and snippets.

@lucamilan
Forked from rithala/Basic-WebRequest.ps1
Created October 24, 2023 13:56
Show Gist options
  • Save lucamilan/92d01e6d0d2bff10b38306d03c277037 to your computer and use it in GitHub Desktop.
Save lucamilan/92d01e6d0d2bff10b38306d03c277037 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