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

Welcome Forums General PowerShell Q&A list failed or succeeded hosts when running invoke-command on remote computers

Viewing 7 reply threads
  • Author
    Posts
    • #189835
      Participant
      Topics: 19
      Replies: 21
      Points: 10
      Rank: Member

      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.

    • #189865
      Participant
      Topics: 0
      Replies: 6
      Points: 79
      Rank: Member

      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.

    • #189868
      Participant
      Topics: 1
      Replies: 1632
      Points: 3,074
      Helping Hand
      Rank: Community Hero

      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. 😉 Please read the complete help including the examples to learn how to use it.

    • #189880
      Participant
      Topics: 0
      Replies: 6
      Points: 79
      Rank: Member

      You can test the connection to a given computer with Test-Connection

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

    • #189955
      Participant
      Topics: 19
      Replies: 21
      Points: 10
      Rank: Member

      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.

    • #190060
      Participant
      Topics: 1
      Replies: 1632
      Points: 3,074
      Helping Hand
      Rank: Community Hero

      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)

    • #190123
      Participant
      Topics: 4
      Replies: 95
      Points: 192
      Helping Hand
      Rank: Participant

      Maybe you could look in to the $error variable?

      $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
      
    • #190147
      js
      Participant
      Topics: 27
      Replies: 716
      Points: 1,881
      Helping Hand
      Rank: Community Hero

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

      icm comp1,comp2,comp3 { pwd } -asjob
      job -inc
      
Viewing 7 reply threads
  • You must be logged in to reply to this topic.