Invoke-Command list of servers not sorted

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Don Jones Don Jones 6 months ago.

  • Author
    Posts
  • #41855
    Profile photo of Harald Cunningham
    Harald Cunningham
    Participant

    Reading computer names from a file. Input file srv.txt lists servers in alphabetical order
    Output ist not sorted as it is in the text file. Is there a way to get output as listed in the text file?

    $Srv = Get-Content -Path "D:\Srv.txt"
    
    Invoke-Command -ComputerName $Srv -ScriptBlock {
        $Comp = Get-WmiObject -Class Win32_ComputerSystem
        $Comp.Name
    
    }
    
  • #41861
    Profile photo of Christian Sandfeld
    Christian Sandfeld
    Participant

    If all you are after is that the output is sorted, you should be able to just pipe the output to Sort-Object

    $Srv = Get-Content -Path "D:\Srv.txt"
    
    Invoke-Command -ComputerName $Srv -ScriptBlock {
        $Comp = Get-WmiObject -Class Win32_ComputerSystem
        $Comp.Name
    
    } | Sort-Object -Property Name
    

    Be aware that piping to sort, means that the entire list of servers will be processed, before you see any output (needs to get all objects through the pipe, before it can do any sorting).

  • #41864
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Keep in mind that Invoke-Command runs parallel, and different computers will respond differently, which is why the sequence changes. Personally I'd put the results in a database – much easier to pull sorts and mess with the data!

  • #41866
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Keep in mind that Invoke-Command runs parallel, and different computers will respond differently, which is why the sequence changes. Personally I'd put the results in a database – much easier to pull sorts and mess with the data!

  • #41868
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Keep in mind that Invoke-Command runs parallel, and different computers will respond differently, which is why the sequence changes. Personally I'd put the results in a database – much easier to pull sorts and mess with the data!

You must be logged in to reply to this topic.