1

I don't understand why this won't work and if someone could explain better for me?

What I want to do is check winmgmt on all servers but it doesn't seem to work with invoke-command because the script runs so quickly, compared to the half minute/minute it takes when logged into an individual server, and more importantly returns inconsistent values.

So my Powershell script:

$list = "serverA", "serverB", "serverC"

foreach ($machine in $list) { invoke-command -computername $machine -command { winmgmt /verifyrepository } }

So the script may return serverA as "Inconsistent" yet if I actually log into the server and run winmgmt then serverA might return "Consistent".

There's got to be something small I am missing but not 100% sure now. I looked on different articles and someone said to not run invoke-command in a foreach but that didn't help.

I tried -scriptblock instead of -command but that didn't work either.

James
  • 303
  • 2
  • 12
  • I would run it this way in parallel but it shouldn't make a difference: `invoke-command -computername $list -scriptblock { winmgmt /verifyrepository }`. There's no "-command" option in invoke-command. – js2010 Nov 29 '20 at 19:39
  • @js2010: `-Command` is an alias of `-ScriptBock` – mklement0 Nov 29 '20 at 19:41
  • 1
    Similar question here suggests wmidiag instead https://social.technet.microsoft.com/Forums/office/en-US/78d69ac9-2bc2-4526-8df6-94ccc093dd5f/powershell-inconsistency-invokecommand-w-quotwinmgmt-verifyrepositoryquot?forum=ITCG – js2010 Nov 29 '20 at 20:04

0 Answers0