问题描述
我正在尝试使用Powershell的-EncodedCommand标志弹出一个简单的消息框,但是它一直失败。我在过去的几个小时里一直尝试使用Google搜索,但似乎无法正常工作。几乎看起来像是一个编码错误,但我使用的是带有标准ASCII向后兼容字符的常规UTF-8。
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.
该命令始终失败:
Powershell.exe -EncodedCommand QWRkLVR5cGUgLUFzc2VtYmx5TmFtZSBQcmVzZW50YXRpb25Db3JlLFByZXNlbnRhdGlvbkZyYW1ld29yaztbU3lzdGVtLldpbmRvd3MuTWVzc2FnZUJveF06OlNob3coJ3dvcmtpbmcnKTs=
b64解码的命令是:
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
推荐答案
Base64编码的字符串传递给 -EncodedCommand
必须对 UTF-16LE ( Unicode)字符串的字节表示进行编码-不不支持UTF-8:
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
这篇关于PowerShell EncodedCommand失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!