So I have a tool I am working on for a team in the company I work for. I get the general concept but I am running into dumb issues which I am sure are due to my own ignorance.
Start-Process -FilePath ping.exe -ArgumentList $WksTxtBox1.Text -t
It works if it doesn't have the -t switch:
Start-Process -FilePath ping.exe -ArgumentList $WksTxtBox1.Text
I have been banging my head against the display trying to figure this out and I know it must be something really simple to get but for the life of me I cannot.
The other issue I am having is similar in that switches are ruining my powershell sanity.
Start-Process -FilePath powershell.exe -ArgumentList -noexit -command enter-pssession -computername $WksTxtBox2.Text
I have tried it with quotes before -noexit and after .Text. But that obviously did not work.
What am I missing? It has to be something simple but I cannot figure it out.
Thank you muchly for your help!
Start-Process -FilePath ping.exe -ArgumentList "$WksTxtBox1.Text -t"
Start-Process -FilePath ping.exe -ArgumentList "$WksTxtBox1.Text","-t"
Unfortunately neither worked.
So it might be the variable or object you're using ($WksTxtBox1.Text). If I run this
Start-Process -FilePath ping.exe -ArgumentList "google.com -t"
Start-Process -FilePath ping.exe -ArgumentList "google.com","-t"
it works just as expected.
That's unfortunate, works fine.
Ok, worked it out.
Start-Process -FilePath ping.exe -ArgumentList $WksTxtBox1.Text,"-t"
Still having issues with the enter-pssession though.
Thanks for your help Olaf!
What do you try to accomplish with this code? Enter-PSSession is made to be used interactively in the console. There are other ways to remote in scripts like Invoke-Command. And you don't need to start a new Powershell process to run another script from "inside" your script.
None of your errors have to do with your GUI, just syntax/quoting isues.
# This fails, becasue you are passing twp params singulalry vs as the expected individual.
This works, because it a single param and expandable.
This fails, becasue of the varible not being expanded in the. It should be this
If you open the above in the ISE or VSCode, you'll note the color coding difference on them and the error indicators.
This works becasue of auto expansion of the var as in the previous example in the double quotes, and you setting the last param properly as a seperate item.
Sometimes I need a remote commandline. And unfortunately PSEXEC does not work on our network.
Thank you for the great explanation on the differences!
Why aren't you using Powershell commands vs Start-Process to start an old command and pass parameters to it:
Test-NetConnection -ComputerName $WksTxtBox1.Text
To make it continous, you just wrap a simple loop around it, like so:
Not to be trite, but I'm still fairly new to this and it was the way I had thought I needed to do it.
I do have another issue now though, hope not to run out my last vestiges of welcome remaining.
I run this command in a straight console:
Get_WmiObject -computer COMPUTERNAME Win32_ComputerSystem | Format-List Name,Domain,Manufacturer,Model,SystemType
I get the following result, which is what I want to see:
Name : COMPUTERNAME
Now if I run the same command in the aforementioned gui like such:
$Results.Text = Get-WmiObject -computer COMPUTERNAME Win32_ComputerSystem | Format-List Name,Domain,Manufacturer,Model,SystemType
I get the following result in Results.Text:
I am sure it's just formatting but I am unsure what it would be.
You have unlimited vestiges of welcomeness. Format-* commands are for making text 'pretty' in the console, so they may not always look good as outputting somewhere else. Some things you can try:
Wrap it in $(), this will execute the code first:
$Results.Text = $(Get-WmiObject -computer COMPUTERNAME Win32_ComputerSystem | Format-List Name,Domain,Manufacturer,Model,SystemType)
Try not to squish it into one line and\or use Out-String to make sure it just text.
$cs = Get-WmiObject -ComputerName COMPUTERNAME -Class Win32_ComputerSystem $output = $cs | Format-List Name,Domain,Manufacturer,Model,SystemType | Out-String $Results.Text = $output
You must be logged in to reply to this topic.