I'm trying to pop up a simple message box using Powershell's -EncodedCommand flag, but it keeps failing. I've tried Googling for the last few hours, but can't seem to get this working. It almost looks like an encoding error, but I'm using regular UTF-8 with standard ASCII backwards-compatible characters.
The command that keeps failing:
Powershell.exe -EncodedCommand QWRkLVR5cGUgLUFzc2VtYmx5TmFtZSBQcmVzZW50YXRpb25Db3JlLFByZXNlbnRhdGlvbkZyYW1ld29yaztbU3lzdGVtLldpbmRvd3MuTWVzc2FnZUJveF06OlNob3coJ3dvcmtpbmcnKTs=
The b64 decoded command is:
Add-Type -AssemblyName PresentationCore,PresentationFramework;[System.Windows.MessageBox]::Show('working');
What am I missing? Thanks for helping with my noob question
The Base64-encoded string passed to -EncodedCommand must encode the byte representation of a UTF-16LE ("Unicode") string - UTF-8 is not supported:
$cmd = 'Add-Type -AssemblyName PresentationCore,PresentationFramework;[System.Windows.MessageBox]::Show(''working'')'
$encodedCmd = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($cmd))
powershell.exe -EncodedCommand $encodedCmd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With