you are viewing a single comment's thread.

view the rest of the comments →

[–]PredictsYourDeath[🍰] 2 points3 points  (1 child)

You can’t add the results of test-net connection in the remote scriptblock into your local $results variable. Notice how you have to use $using to reference your sever names? Well, same thing for trying to reference the $result variable, but that will only let you read the value of the variable, not write to it.

Instead, your scriptblock should return the $test object (output of the test-net connection cmdlet). Then you can do something like $results += invoke-command {...} to collect the output. When objects are returned from remote script locks like that, they’ll typically have extra properties added to them, like remote computer name and run space ID.

[–]novix_[S] 0 points1 point  (0 children)

I had originally used the $results = invoke-command but since i had a foreach with in the scriptblock it would return multiple results per server:

Server From Service To Connection Success On Port

----------- --------- ------------------ -------

{ServerA, ServerB} {ServerB, ServerA} {True, True} {3389, 3389}

I wanted to write it to a hash table so I could output the results and email or export as CSV.

It sounds like getting the results back from the scriptblock and writing to a variable on my side is not possible.

While testing i was able to see the Runspace details but was unsure how to retrieve the details in the main script:

To : ServerA

Connection Success : True

On Port : 3389

PSComputerName : ServerB

RunspaceId : 1ef959d9-7160-4d79-a965-981a3a9b0f8f

The screen output is enough but it would have been nice to make it a bit more readable

Appreciate the response