Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell EncodedCommand Failing

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

like image 500
PSHelper12 Avatar asked Dec 20 '25 17:12

PSHelper12


1 Answers

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
like image 50
mklement0 Avatar answered Dec 23 '25 06:12

mklement0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!