Private/ConvertTo-BasicAuth.ps1

1
2
3
4
5
6
7
8
9
10
11
12
function ConvertTo-BasicAuth {
    param (
        [String] $Username,
        [SecureString] $Password
    )

    $creds = [System.Management.Automation.PSCredential]::new($Username,$Password).GetNetworkCredential()
    $credPair = "$($creds.UserName):$($creds.Password)"
    $encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
    return $encodedCredentials
}