0

I am still trying to adjust to powershell after a couple of days playing around with it.

I have the following question regarding invoke-command. My scenario is this: I am trying to make use of the invoke-command and its ability to "thread" to multiple computers at once when we pass a list of computers to it:

$ipList=@()
invoke-command $ListOfComputers -ScriptBlock {
    #do something, following is an imaginary cmdlet
$ipList+=get-ip-of-machine
}

I want to keep track of which of those computers it can not connect to. Is there a way to catch those exceptions? Or would i have to connect to one computer at a time and, test-connection and perhaps have invoke-command run as a job to make it faster?

try {} catch {} didn't seem to work.

Nick
  • 4,302
  • 2
  • 24
  • 38
user79089
  • 23
  • 2
  • 4

1 Answers1

0

how about below command, test-connection could receive an array of computer as parameter

$res = Test-Connection server1,server2 -Count 1 -ThrottleLimit 10 -AsJob | Wait-job | receive-job | ? {-not ($_.ResponseTime -eq $null)} | select Address

Jackie
  • 2,476
  • 17
  • 20
  • hmm, i could test to see if the machine is alive, which would solve one problem, is there a way to check to make sure that the machine can also be connected to for remoting? – user79089 Nov 01 '12 at 11:08
  • I think you need to new-pssession for each machine one by one – Jackie Nov 01 '12 at 11:24
  • I was hoping that the fan-out feature would offer the ability for error catching. I think i will look into the -asjobs feature and how i can work with that. Thank you for your time and help – user79089 Nov 01 '12 at 12:59