functions/ConvertTo-Base64.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Function ConvertTo-Base64 {
    <#
        .SYNOPSIS
        Encode strings to Base64 format
 
        .DESCRIPTION
        Helper function to manage base64 encoded strings
    #>

    param(
        [Parameter(ValueFromRemainingArguments)]
        [String] $Input,
        [Parameter(ValueFromPipeline)]
        [String] $PipelineInput
    )
    begin {
        if($Input){ return $Input | ConvertTo-Base64 }
    }
    process {
        $b = [System.Text.Encoding]::UTF8.GetBytes($PipelineInput)
        return [System.Convert]::ToBase64String($b)
    }
}

Export-ModuleMember -Function ConvertTo-Base64