PowerShell – HTTP Authentication

#Authentication Parameters
#Credential used after initial communication
$Credentials=Get-Credential
#Building Authorisation Header for initial communication not used afterwards
$Base64Auth=[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Credentials.GetNetworkCredential().username + ":" + $Credentials.GetNetworkCredential().password ))
$BasicCredentials = "Basic " + $Base64Auth
$headers = @{"tenant-code" = $tenantAPIKey; "Authorization"= $BasicCredentials}
$Output = Invoke-RestMethod -Method Post -Credential $Credentials -Uri $URI -Body $Body -ContentType $ContentType -Headers $headers 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.