I would like to execute an encoded powershell-script from a Windows-batch and pass a parameter to it.
Let's take for example the following script:
param (
$foo
)
Write-Host("Hello World!" + $foo)
When encoding it to base64, the result is:
cABhAHIAYQBtACAAKAANAAoAIAAgACAAIAAkAGYAbwBvAA0ACgApAA0ACgBXAHIAaQB0AGUALQBIAG8AcwB0ACgAIgBIAGUAbABsAG8AIABXAG8AcgBsAGQAIQAiACAAKwAgACQAZgBvAG8AKQA=
I do then create a batch-skript:
@ECHO OFF
powershell.exe -EncodedCommand "cABhAHIAYQBtACAAKAANAAoAIAAgACAAIAAkAGYAbwBvAA0ACgApAA0ACgBXAHIAaQB0AGUALQBIAG8AcwB0ACgAIgBIAGUAbABsAG8AIABXAG8AcgBsAGQAIQAiACAAKwAgACQAZgBvAG8AKQA="
How can I pass a parameter to the powershell to make it output a value for $foo after "Hello World!"?
Due to the circumstances, I cannot create another script-file or anything similar. The whole process should be contained in the BAT-file.