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.