Skip to content

Instantly share code, notes, and snippets.

@mikebranstein
Created September 1, 2016 22:23
Show Gist options
  • Save mikebranstein/5c147cece94a6ec4b0f055ea713cb554 to your computer and use it in GitHub Desktop.
Save mikebranstein/5c147cece94a6ec4b0f055ea713cb554 to your computer and use it in GitHub Desktop.
make an web request using basic authentication in powershel
function Invoke-AuthenticatedWebRequest {
param (
[string] $uri,
[string] $userName,
[string] $password,
[string] $method,
[string] $contentType
)
$credentials = "$($userName):$($password)"
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credentials))
$basicAuthValue = "Basic $encodedCredentials"
$headers = @{
Authorization = $basicAuthValue
}
Invoke-WebRequest -Uri $uri -Headers $headers -Method $method -ContentType $contentType -DisableKeepAlive
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment