Powershell 远程处理 C# 调用表达式
由于此方法不起作用,我正在尝试一种非常复杂的方法来获取远程计算机上的完整路线信息。我正在尝试连接到远程 powershell 运行空间并以这种方式执行route.exe 命令行工具并返回信息。
本质上,我正在应用此处找到的解决方案,除了我正在尝试运行命令: Invoke-Expression "c:\WINDOWS\system32\route.exe print" 而不是“get-process”
当我使用“get-process”时它可以工作。当我尝试 Invoke-Expression 时,出现异常,告诉我无法找到此命令。当我在本地计算机上运行完全相同的命令时,它会起作用并显示路由信息。所以我知道这不是语法问题或路径中的拼写错误。有谁知道为什么会发生这种情况?
谢谢。
As a result of this approach not working, I am trying a very convoluted way of getting complete route information on a remote machine. I am trying to connect to a remote powershell runspace and execute the route.exe command line tool that way and return the information.
Essentially I am applying the solution found here except I am trying to run the command: Invoke-Expression "c:\WINDOWS\system32\route.exe print"
instead of "get-process"
When I use "get-process" it works. When I try Invoke-Expression I get an exception telling me that this command-let cannot be found. When I run the exact same command on the machine locally, it works and the routing information is displayed. So I know it's not a syntax problem or a typo in the path. Does anyone know why this is happening?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,当我发布这篇文章时,我就有了一个绝妙但显而易见的想法。从技术上讲,“Invoke-Expression”是“命令”,“c:\WINDOWS\system32\route.exe print”是命令的参数。因此,您需要将其添加到我上面链接到的代码中:
其中 scriptText 是“Invoke-Expression”,args 是“c:\WINDOWS\system32\route.exe print”。
希望这对某人有帮助!
Okay, so as soon as I posted this I had a brilliant, but obvious, idea. Technically the "Invoke-Expression" is the 'command' and the "c:\WINDOWS\system32\route.exe print" is an argument of the command. So you need to add this to the code that I linked to above:
Where scriptText is the "Invoke-Expression" and args is "c:\WINDOWS\system32\route.exe print".
Hope this helps someone!
一点:您是否正确转义了所有
\
?另一点:尝试 Invoke-Command 而不是 Invoke-Expression
one point: have you escaped all
\
correctly ?another point: try Invoke-Command instead of Invoke-Expression