list failed or succeeded hosts when running invoke-command on remote computers

when running invoke-command against computers some are sleeping and the command fails on them. how can powershell output a “report” of failed or succeeded hosts.

Hi Garegin,

Look at the foreach and try\catch constructs. Foreach to loop through each device your connecting against, TRY to connect and Catch to log failures. Hope that helps.

You can test the connection to a given computer with Test-Connection. If you do this before you invoke commands you can avoid these kind of errors. :wink: Please read the complete help including the examples to learn how to use it.

This work well if you’re certain that ICMP is allowed through out your network.

thanks for the answers. I’ve heard somewhere that you can make powershell indicate the name of the host the command response came from. So if you try to find ram RAM size, the return output would indicated which size belongs to which machine.

Is that another question? If yes - you might create a new thread for it. Did you try to search for it? Please show your code. (formatted as code, please)

Maybe you could look in to the $error variable?

[pre]
$error.Clear()
Invoke-Command -ComputerName superServer,notexist01,notexist02 -ScriptBlock {get-process | select -first 1 processname} -ErrorAction SilentlyContinue
ProcessName PSComputerName RunspaceId


AdmPwd.UI superServer 58d1cf75-9b61-40ff-99bf-c41d621833fe
$error.targetobject
notexist02
notexist01
[/pre]

If you run the commands as jobs, it should be easy to see which ones fail.

icm comp1,comp2,comp3 { pwd } -asjob
job -inc