Powershell: Executing Base64 commands returns error?

Dan*_*iel 5 powershell

I need help with a simple test case of executing a CLI command through PowerShell which has already been encoded in Base64.

Suppose Get-ChildItem has been converted in advance to Base64 string R2V0LUNoaWxkSXRlbQ==.

Further suppose I have a DOS CLI instance open, and I want to test executing this string in powershell:

C:>\ powershell.exe -enc R2V0LUNoaWxkSXRlbQ==
Run Code Online (Sandbox Code Playgroud)

However, I receive the following error:

The term '???????' 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:8
*??????? <<<<
    + CategoryInfo        :ObjectNotFound: (???????:String) [], CommandNotFoundException
    + FullyQualifiedErrorID: CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

我知道有一种方法可以引入变量的使用,甚至包括编码过程本身。但我想知道的是,这种方法可以挽救吗?我可能做错了什么?我在 Win7 中运行 PS 2.0 版。

Som*_*lse 7

如果必须对其进行编码,请使用以下命令获取 Base64 字符串:

[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes('Get-ChildItem'))
Run Code Online (Sandbox Code Playgroud)

尝试这对我有用:

powershell.exe -encodedCommand RwBlAHQALQBDAGgAaQBsAGQASQB0AGUAbQA=
Run Code Online (Sandbox Code Playgroud)

  • 在旁注中,我确实注意到提供 Base64 编码的网站提供了您使用的错误字符串。我会避免使用此类方法对 Base64 字符串进行编码,并坚持使用您打算使用它们的工具中提供的编码功能。 (2认同)
  • 这是因为这些网站使用 UTF-8,而 PowerShell 只接受 UTF-16 编码的字符串[ (2认同)