-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvertTo-Base64.ps1
41 lines (40 loc) · 1.35 KB
/
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Function ConvertTo-Base64{
<#
.Synopsis
Converts a plaintext string in to Base64.
.Description
Takes a plaintext string as a parameter, either directly or from the pipeline, and converts it in to Base64.
.Parameter TextString
The plaintext string. Can come from the pipeline.
.Parameter Bytes
Bytes to be directly converted to Base64
.Parameter Encoding
Default encoding is UTF8, but this can be Unicode, ASCII or UTF8 if you're having problems.
.NOTES
Version: 1.0
Author: C. Bodett
Creation Date: 9/14/2021
Purpose/Change: Initial function development.
#>
[cmdletbinding()]
Param (
[Parameter(ValueFromPipeline = $true, Position = 0, Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[String]$TextString,
[Parameter(ValueFromPipeline = $false, Position = 0, Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[Byte[]]$Bytes,
[Parameter(Position = 1)]
[ValidateSet('UTF8','Unicode','ASCII')]
[String]$Encoding = 'UTF8'
)
Switch ($PSBoundParameters.Keys) {
'TextString' {
$Encoded = [System.Convert]::ToBase64String([System.Text.Encoding]::$Encoding.GetBytes($TextString))
}
'Bytes' {
$Encoded = [System.Convert]::ToBase64String($Bytes)
}
}
$Encoded
}