invoke command returns no results for get-hotfix

This topic contains 7 replies, has 4 voices, and was last updated by  Pradeep Arora 5 days, 6 hours ago.

  • Author
    Posts
  • #81680

    Jon
    Participant
    Invoke-Command -ComputerName (gc C:\scripts\computers.txt) -scriptblock {get-hotfix | select-string 4038799}

    When I run this against my list of servers I see the shell start moving like it's outputting something, but nothing comes up. No errors either. I can manually enter a PS session to any one of the servers, run the command and it outputs that the hotfix is there.

    I can run this command and everything shows up fine.

    Invoke-Command -ComputerName (gc C:\scripts\computers.txt) -scriptblock {net localgroup administrators}

    Has anyone else seen this? Is there another way I should be handling this?

  • #81686

    Don Jones
    Keymaster

    Try connecting to the same machine using Enter-PSSession and running the same Get-Hotfix command. Do you get anything then?

  • #81691

    Jon
    Participant

    Yep that works fine

  • #81695

    Don Jones
    Keymaster

    OK, so the command you're sending works. So the only difference between your Invoke-Command and your Enter-PSSession is that the former is targeting multiple computers, whereas the latter is targeting only one computer, right? Could we test the Invoke-Command with just one computer – the same one you used for Enter-PSSession?

  • #81698

    Jon
    Participant

    Yep, tried that as well (Sorry, I should have listed all the troubleshooting I did!) and it doesn't work. Gives me the same blank output.

    Should I be doing some type of for each on enter-pssession?

  • #81838

    Jeremy Murrah
    Participant

    That's pretty interesting. I was able to duplicate that error and it seems to be something with select-string. As an aside you could try this command if you're just trying to find out if a hotfix is installed. The output is a little different than your first command but the logic is essentially the same

    Invoke-Command -ComputerName (gc C:\scripts\computers.txt) -scriptblock {get-hotfix -id kb4038799}
    

    Now what's weird about the select-string thing is that if you add a format-list * to your command you get the output. Likewise if you pipe it to get-member. It appears to be just an output view thing, so this works too:

    Invoke-Command -ComputerName (gc C:\scripts\computers.txt) -scriptblock {get-hotfix | select-string 4038799 | format-list *}
    

    Edit:
    Found a good explanation here: https://social.technet.microsoft.com/Forums/scriptcenter/en-US/f5697b54-6256-4489-80e1-18b1a7d3cb56/selectstring-in-invokecommand-not-working-as-expected?forum=ITCG

    The issue is caused by the '$matches' collection. It does not seem portable across sessions. This is because it is an array of pointers into some objects stashed in memory. When returned to a remote session it points to nothing for some reason so we get a list of null or zeros which show up as line feeds.

    Adding the select forces a simle object to be created containing the string. This can be ported to a remote session.

    So in addition to format-list * you could use select line or select anything really. That's an interesting "feature"

    • #81982

      Jon
      Participant

      Thanks Jeremy, never thought to do it that way!

  • #82066

    Pradeep Arora
    Participant

    This is more for learning – am I missing something?

    I don't see a ToString() in Get-HotFix and that's what help for Select-String says for Input it expects, hence it returns nothing.

You must be logged in to reply to this topic.