If you use PowerShell remoting to receive information from remote machines, you can use fan-out simply by specifying more than one computer name. PowerShell will then automagically contact all machines simultaneously, which saves a lot of time (all of this requires that you have set up and enabled PowerShell on the affected machines, of course, which is not covered here).
The results come back in random order because all contacted machines return their information to you when they are ready.
To separate result data again per computer, use Group-Object:
$pc1 = $env:computername
$pc2 = '192.168.2.112'
Get-Service | Where-Object Status -eq Running
# get all results
$result = Invoke-Command -ScriptBlock $code -ComputerName $pc1, $pc2
# separate per computer
$groups = $result | Group-Object -Property PSComputerName -AsHashTable
# access per computer results separately
When you specify -AsHashTable, Group-Object creates a hash table and uses the computer name as key. This way, you can use the time-saving parallel processing and still consume results per computer.
ReTweet this Tip!
It's also best to start a new question thread so those who wish to respond have more flexibility to respond more fully.
OK, what is now needed is your code block you are using.
Yes, tried that...
If I apply a sort to the output string, I get the row of titles, row of underlines, then a row of data... Then, for the next item, another row of titles/underlines/data - repeated until the end of the array.
If I move the sorted output string further into my nested arrays, I get the same line repeated over and over...
If I don't apply a sort, I get two servers where the output line is repeated, among the rest of the data.
Have you already tried using the Sort-Object cmdlet in your code for your use case?
Sort # means ascending
You can also view the blog post called 'Working with Hash Tables' on TechNet's 'Windows PowerShell Tip of the Week', which also talk to the above when hash tables are used.
I'm trying to do something similar, but building hash table using output of various objects... I can't figure out how to alphabetise and '-unique' the output. Would you be able to help?
Powered by IDERA