Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#

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:

C#

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 '+'.
Posted
Updated 3-Sep-16 23:13pm

1 solution

Finally I got it to work:

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

I was the double quotes.

Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900