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.
First:
I would like to start a continuos ping session in an external window. I can get it to work for a regular session, 4 results and done then the window auto closes. When I try to pass the -t switch is when powershell farts out an error. The command goes like this:
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.
What I have is this:
Unfortunately neither worked.
The first one cause an error.
The second however ran but the resultant window closed immediately after opening. Too quickly to see anything inside the window.
Sorry man. =(
Still having issues with the enter-pssession though.
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.
This fails, becasue you are passing twp params singulalry vs as the expected individual.
$WksTxtBox1.Text
This works, because it a single param and expandable.
"$WksTxtBox1.Text -t"
This fails, becasue of the varible not being expanded in the. It should be this
"$($WksTxtBox1.Text) -t"
If you open the above in the ISE or VSCode, you’ll note the color coding difference on them and the error indicators.
$WksTxtBox1.Text,"-t"
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.
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.
Sometimes I need a remote commandline. And unfortunately PSEXEC does not work on our network.
I have thought about the issue and, normally, invoking a single command isn't what I need in order to get the result I require. Since I am using a GUI, spawning another powershell session with a remote console connection is currently my best option.
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.
Now that being said it was also a challenge from a friend so I wanted to show him It could be done. Thanks to you guys he -might- shutup about it now haha.
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: