Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Forloop does not continue if cmdlet fails

$
0
0

Dear All,

pretty new to powershell, might be a simple question, i'm trying to iterate a list of computers to find event logs and store them in an array, however if get-winevent fails for somereason, the next server in the list does not continue, please suggest.

foreach ($server in $servers)
         {

if (test-connection $server -quiet)
              {

   $arr1+= Get-WinEvent -computername $server -MaxEvent 100 -FilterHashtable @{Logname="System"; ProviderName="Microsoft-Windows-WindowsUpdateClient"; ID=19,20;StartTime=(Get-Date).AddHours(-24)} |select Machinename,TimeCreated,ID,Message
               }


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>