Goal:
I am attempting to a find a solution that would allow me to enter a Base64 encoded string that can be multiple lines. The goal is to decode the string and get the output returned in the powershell console. Originally, I called a WinForms dialogue, however, this is not possible with implicit remoting.
This is what I have so far:
function Get-Base64 {
Write-Host 'Decode:' -ForegroundColor Yellow -NoNewline
$data = Read-Host
$decode = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("$data"))
$decode.ToString()
}
I get the following error message when entering multiple lines:
PS > Get-Base64
Decode)ZXZhbChmdW5jdGlvbihwLGEsYyxrLGUsZCl7ZT1mdW5jdGlvbihjKXtyZXR1cm4oYzxhPycnOmUo
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(
PS > cGFyc2VJbnQoYy9hKSkpKygoYz1jJWEpPjM1P1N0cmluZy5mcm9tQ2hhckNvZGUoYysyOSk6Yy50
cGFyc2VJbnQoYy9hKSkpKygoYz1jJWEpPjM1P1N0cmluZy5mcm9tQ2hhckNvZGUoYysyOSk6Yy50 : The term 'cGFyc2VJbnQoYy9hKSkpKygoYz1jJWEpPjM1P1N0cmluZy5mcm9tQ2hhckNvZGUoYysyOSk6Yy50' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ cGFyc2VJbnQoYy9hKSkpKygoYz1jJWEpPjM1P1N0cmluZy5mcm9tQ2hhckNvZGUoYysyO ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (cGFyc2VJbnQoYy9...GUoYysyOSk6Yy50:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
You can see that it decoded the first part then on the next line, read it as a cmdlet.
Question:
How can I avoid formatting collisions to decode multiple lines?