Functions/Data/ConvertTo-Base64.ps1
<#
.SYNOPSIS Converts a value to base-64 encoding. #> function ConvertStringTo-Base64 { [CmdletBinding()] param ( # The value to base-64 encode [Parameter(Mandatory=$true,ValueFromPipeline=$true)] [AllowNull()] [AllowEmptyString()] [string[]] $Value, # The encoding to use. Default is UTF8 [Parameter(Mandatory=$false)] [ValidateSet("UTF8","Unicode","ASCII","UTF7","UTF32","BigEndianUnicode")] [string] $Encoding = "UTF8" ) Begin { [Text.Encoding]$Encode = ([System.Text.Encoding]::$Encoding) } process { $Value | ForEach-Object { if( $_ -eq $null ) { return $null } $bytes = $Encode.GetBytes($_) [Convert]::ToBase64String($bytes) } } } |