Skip to content

Instantly share code, notes, and snippets.

@itsthedoc
itsthedoc / Test-IWRBasicAuth.ps1
Created November 22, 2017 15:59
Powershell example script to create headers to submit an HTTP request with basic auth
$user = "USERNAME"
$pass = "PASSWORD"
$pair = "${user}:${pass}"
#Encode the string to the RFC2045-MIME variant of Base64, except not limited to 76 char/line.
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
#Create the Auth value as the method, a space, and then the encoded pair Method Base64String
$basicAuthValue = "Basic $base64"