invoke command returns no results for get-hotfix

This topic contains 7 replies, has 4 voices, and was last updated by  Pradeep Arora 7 months, 2 weeks ago.

  • Author
  • #81680

    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

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

  • #81691


    Yep that works fine

  • #81695

    Don Jones

    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


    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

    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 *}

    Found a good explanation here:

    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


      Thanks Jeremy, never thought to do it that way!

  • #82066

    Pradeep Arora

    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.