# Using invoke-command on multiple workstations, how do I ignore the errors?

**URL:** <https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457>\
**Category:** PowerShell Help\
**Created:** [February 18, 2025, 7:16pm UTC](https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457 "2025-02-18T19:16:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![GrandeAnde](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grandeande/32/5885_2.png) [@GrandeAnde](https://forums.powershell.org/u/GrandeAnde)\
**Post date:** [February 18, 2025, 7:16pm UTC](https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457/1 "2025-02-18T19:16:16Z")

</div>

So I am running invoke-command against multiple computers using an array. I am trying to find workstations with a specific file on them. This works great. I can get a list of 5 workstations with this file, and I have the data I need. However, it also outputs 95 instances of results being produced in red lines telling me file not found. How do I manage error handling to ignore this kind of stuff? I just want the positive output, not errors.

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [February 18, 2025, 7:23pm UTC](https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457/2 "2025-02-18T19:23:38Z")

</div>

It helps if you post your code you’re working with and make sure to format it with the ‘\</\>’ button

---

<div class="post-metadata">

**Author:** ![GrandeAnde](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grandeande/32/5885_2.png) [@GrandeAnde](https://forums.powershell.org/u/GrandeAnde)\
**Post date:** [February 18, 2025, 7:41pm UTC](https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457/4 "2025-02-18T19:41:32Z")

</div>

```auto
<$computers = Get-ADComputer -filter * -SearchBase "ou=some,ou=ou workstations,dc=domain,dc=coml" | select-object -Property dnshostname -ExpandProperty dnshostname
Invoke-Command -ComputerName $computers -Credentials domain\admin -ScriptBlock {Get-WmiObject -class win32_product | Where-Object {$_.name -like "*name*"}} -erroraction silentlycontinue>

```

This works great… I get the data I need but then get tons of output like this for the other computers that don’t have that info:

```auto
<[COMPUTER.DOMAIN.] Connecting to remote server COMPUTER.DOMAIN failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is 
accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local 
subnet. For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo : OpenError: ([COMPUTER.DOMAIN:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken>

```

Pretty much, I want to ignore all of that in my output so I can get a cleaner presentation of the data I need without the data I **DON’T** need.

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [February 18, 2025, 7:51pm UTC](https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457/5 "2025-02-18T19:51:32Z")

</div>

ErrorAction SilentlyContinue only handles non-terminating errors.

You can add to ignore the errors

```auto
try {
Invoke-Command....
} catch {}
```

---

<div class="post-metadata">

**Author:** ![Christophe](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@Christophe](https://forums.powershell.org/u/Christophe)\
**Post date:** [February 18, 2025, 8:46pm UTC](https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457/6 "2025-02-18T20:46:08Z")

</div>

hello,  
why not also put a try-catch block in the script block. This prevent remote computers to return error to calling computer.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [February 18, 2025, 9:12pm UTC](https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457/7 "2025-02-18T21:12:23Z")

</div>

I use this pattern

```auto
Invoke-Command -ComputerName $computerlist -ScriptBlock $script -ErrorAction SilentlyContinue -ErrorVariable +errors

```

This will prevent errors generated by Invoke-Command while collecting the errors in the $errors varialbe so you can look at them afterwards if you like. The + sign on the variable name makes the errors append to the variable, otherwise it will overwrite.

---

<div class="post-metadata">

**Author:** ![GrandeAnde](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grandeande/32/5885_2.png) [@GrandeAnde](https://forums.powershell.org/u/GrandeAnde)\
**Post date:** [February 19, 2025, 12:25pm UTC](https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457/8 "2025-02-19T12:25:50Z")

</div>

This is nice, I like that you can store them later for review. Thank you!

---

<div class="post-metadata">

**Author:** ![GrandeAnde](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grandeande/32/5885_2.png) [@GrandeAnde](https://forums.powershell.org/u/GrandeAnde)\
**Post date:** [February 19, 2025, 12:26pm UTC](https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457/9 "2025-02-19T12:26:25Z")

</div>

This did it, thank you!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [March 21, 2025, 12:26pm UTC](https://forums.powershell.org/t/using-invoke-command-on-multiple-workstations-how-do-i-ignore-the-errors/25457/10 "2025-03-21T12:26:27Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
