Last active
August 22, 2018 11:54
-
-
Save Geogboe/c0692fecf66ee254a3b5d4040f36b60f to your computer and use it in GitHub Desktop.
Function to convert a PSCredential to a Basic Auth encoded credential
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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