Skip to content

Instantly share code, notes, and snippets.

@Geogboe
Last active August 22, 2018 11:54
Show Gist options
  • Save Geogboe/c0692fecf66ee254a3b5d4040f36b60f to your computer and use it in GitHub Desktop.
Save Geogboe/c0692fecf66ee254a3b5d4040f36b60f to your computer and use it in GitHub Desktop.
Function to convert a PSCredential to a Basic Auth encoded credential
function ConvertTo-BasicAuth {
[cmdletbinding()]
param (
[Parameter( ValueFromPipeline )]
[PSCredential]
$Credential
)
$Username = $Credential.UserName
$Password = $Credential.GetNetworkCredential().Password
$AuthPair = $Username + ":" + $Password
return ( [System.Convert]::ToBase64String( [System.Text.Encoding]::ASCII.GetBytes( $AuthPair )))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment