Functions/ConvertFrom-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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
function ConvertFrom-Base64 { <# .SYNOPSIS Convert from a Base64 string to normal string .DESCRIPTION Convert from a Base64 string to normal string. Function aliased to 'Base64Decode'. .PARAMETER Base64 A base64 encoded string .PARAMETER IncludeInput Switch to enable including the input to appear in the output .EXAMPLE ConvertFrom-Base64 "SABlAGwAbABvAA==" Would return Hello .EXAMPLE ConvertFrom-Base64 "SABlAGwAbABvAA==" -IncludeInput Would return Base64 String ------ ------ SABlAGwAbABvAA== Hello .OUTPUTS [string[]] #> #region Parameter [CmdletBinding(ConfirmImpact='None')] [alias('Base64Decode')] Param( [Parameter(Position = 0, Mandatory, ValueFromPipeLine)] [string[]] $Base64, [switch] $IncludeInput ) #endregion Parameter begin { Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]" } #close begin block process { foreach ($curBase64 in $Base64) { $bytesfrom = [Convert]::FromBase64String($curBase64) $decodedfrom = [Text.Encoding]::Unicode.GetString($bytesfrom) if ($IncludeInput) { New-Object -TypeName psobject -Property ([ordered] @{ Base64 = $curBase64 String = $decodedfrom }) } else { Write-Output -InputObject $decodedfrom } } } end { Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]" } } |