Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-AuthorizationHeader
- {
- [cmdletbinding()]
- Param(
- [Parameter(
- ValueFromPipeline)]
- [PSCredential]
- $Credential
- )
- Begin
- {
- $f = $MyInvocation.InvocationName
- Write-Verbose -Message "$f - START"
- }
- Process
- {
- if (-not $Credential)
- {
- Write-Warning -Message "Credential parameter is null"
- return
- }
- $userName = $Credential.GetNetworkCredential().UserName
- $pass = $Credential.GetNetworkCredential().Password
- $domain = $Credential.GetNetworkCredential().Domain
- [string]$authString = "$($userName):$pass"
- if (-not [string]::IsNullOrEmpty($domain))
- {
- [string]$authString = "$($userName)@$($domain):$pass"
- }
- $auth = $authString | ConvertTo-Base64
- @{
- "Authorization" = "Basic $auth"
- }
- }
- End
- {
- Write-Verbose -Message "$f - END"
- }
- }
- function ConvertTo-Base64
- {
- [cmdletbinding()]
- Param(
- [Parameter(
- Mandatory,
- ValueFromPipeline)]
- [string[]]
- $InputObject
- )
- Begin
- {
- $f = $MyInvocation.InvocationName
- Write-Verbose -Message "$f - START"
- }
- Process
- {
- foreach ($string in $InputObject)
- {
- $bytes = [System.Text.Encoding]::UTF8.GetBytes($string)
- [System.Convert]::ToBase64String($bytes)
- }
- }
- End
- {
- Write-Verbose -Message "$f - EMD"
- }
- }
Add Comment
Please, Sign In to add comment