invoke command returns no results for get-hotfix

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?

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

Yep that works fine

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?

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?

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”

Thanks Jeremy, never thought to do it that way!

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.