来自C#的Powershell命令

编程入门 行业动态 更新时间:2024-10-14 02:25:08
本文介绍了来自C#的Powershell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从C#运行这个powershell命令 PS> test-Dtc -LocalComputerName$ env:COMPUTERNAME-RemoteComputerNamemyRemotePC-ResourceManagerPort 17100 -Verbose 并将输出放入list2 我尝试了什么: 我尝试了谷歌的一些推荐。包括 PowerShell ps = PowerShell.Create(); ps.AddCommand(Test-Dtc); ps.AddArgument( - LocalComputerName \$ env:COMPUTERNAME \-RemoteComputerName \Remotepc \-ResourceManagerPort 17100 -Verbose); foreach(PSObject结果在ps.Invoke()中) { listBox2。 Items.Add(result); } //结束foreach。 但到目前为止没有运气。 任何帮助将不胜感激

I would like to run this powershell command from C# PS> test-Dtc -LocalComputerName "$env:COMPUTERNAME" -RemoteComputerName "myRemotePC" -ResourceManagerPort 17100 -Verbose and put output in list2 What I have tried: I tried several recommendations from google.including PowerShell ps = PowerShell.Create(); ps.AddCommand("Test-Dtc"); ps.AddArgument("-LocalComputerName \"$env:COMPUTERNAME\" -RemoteComputerName \"Remotepc\" -ResourceManagerPort 17100 -Verbose"); foreach (PSObject result in ps.Invoke()) { listBox2.Items.Add(result); } // End foreach. but no luck so far. Any help would be greatly appreciated

推荐答案

env:COMPUTERNAME-RemoteComputerNamemyRemotePC - ResourceManagerPort 17100 -Verbose 并将输出列入清单2 我尝试过: 我尝试了谷歌的一些推荐。包括 PowerShell ps = PowerShell.Create(); ps.AddCommand(Test-Dtc); ps.AddArgument( - LocalComputerName \ env:COMPUTERNAME" -RemoteComputerName "myRemotePC" -ResourceManagerPort 17100 -Verbose and put output in list2 What I have tried: I tried several recommendations from google.including PowerShell ps = PowerShell.Create(); ps.AddCommand("Test-Dtc"); ps.AddArgument("-LocalComputerName \"

env: COMPUTERNAME \-RemoteComputerName \Remotepc \-ResourceManagerPort 17100 -Verbose); foreach(PSObject in ps.Invoke()) { listBox2.Items.Add(result); } //结束foreach。 但到目前为止没有运气。 任何帮助将不胜感激 env:COMPUTERNAME\" -RemoteComputerName \"Remotepc\" -ResourceManagerPort 17100 -Verbose"); foreach (PSObject result in ps.Invoke()) { listBox2.Items.Add(result); } // End foreach. but no luck so far. Any help would be greatly appreciated

是的,您应该看到运行时异常: Yes, you should be seeing a runtime exception: 引用:

System.Management.Automation.RuntimeException 发生 HResult = 0x80131501 Message = - LocalComputerName

System.Management.Automation.RuntimeException occurred HResult=0x80131501 Message="-LocalComputerName "

更多推荐

来自C#的Powershell命令

本文发布于:2023-11-07 23:37:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567742.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   Powershell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!