视觉工作室2015中的Powershell变量 [英] Powershell variable in visual studio 2015

查看:80
本文介绍了视觉工作室2015中的Powershell变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我点击Winform上的按钮时,它会读取一个Powershell字符串并执行得很好并将结果显示到我的输出文本框( textBoxOutput.Text



字符串:

 

textBoxOutput.Text = RunScript(Get-Process -ComputerName NameOfComputer | Where-Object {$ _ .response -eq $ false} |格式表 - 自动化状态,进程名称,内存,CPU);



我一直试图做的是在表单中添加一个文本框我可以在其中输入 computername 并将其传递到上面的字符串中,因此我不必在字符串中对 computername 进行硬编码。



任何帮助表示赞赏。



问候,



我尝试过:



 

textBoxOutput.Text = RunScript (Get-Process -ComputerName + variable + | Where-Object {$ _ .response -eq $ fal se} | Format-Table -AutoSize Status,ProcessName,Memory,CPU);



收到错误:



脚本错误:找不到接受参数'+'的位置参数。

解决方案

_ .response -eq


< blockquote> false} | Format-Table -AutoSize Status,ProcessName,Memory,CPU);



我一直试图做的是添加我可以输入计算机名称并将其传递到上面的字符串中的文本框,这样我就不必在字符串中对计算机名称进行硬编码。 />


任何帮助表示赞赏。



问候,



我尝试过:



 

textBoxOutput.Text = RunScript(Get-Process -ComputerName + variable + | Where-Object {


_ .response -eq


Hi,

When I click the button on my Winform it reads a Powershell string and executes just fine and displays the results to my out put textbox (textBoxOutput.Text)

The string:

textBoxOutput.Text = RunScript("Get-Process -ComputerName NameOfComputer | Where-Object {$_.responding -eq $false} | Format-Table -AutoSize Status, ProcessName, Memory, CPU");

What I have been trying to do, is add a textbox to the form where I can enter the computername and pass it into the string above so I don't have to have the computername hard coded in the string.

Any help is appreciated.

Regards,

What I have tried:

textBoxOutput.Text = RunScript("Get-Process -ComputerName + variable + | Where-Object {$_.responding -eq $false} | Format-Table -AutoSize Status, ProcessName, Memory, CPU");

I receive the error:

Error in script : A positional parameter cannot be found that accepts argument '+'.

解决方案

_.responding -eq


false} | Format-Table -AutoSize Status, ProcessName, Memory, CPU");

What I have been trying to do, is add a textbox to the form where I can enter the computername and pass it into the string above so I don't have to have the computername hard coded in the string.

Any help is appreciated.

Regards,

What I have tried:

textBoxOutput.Text = RunScript("Get-Process -ComputerName + variable + | Where-Object {


_.responding -eq


这篇关于视觉工作室2015中的Powershell变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆