• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

I can't seem to catch this error on Server 2003



Below I use this because a timeout throws and I simple want null to
return if a timeout occurs.

if (&{$ErrorActionPreference = 'SilentlyContinue'
$MEW.WaitForNextEvent()}) {

This worked on my desktop (XP) but on Server 2003 I get
"WaitForNextEvent" with "0" argument(s): "Timed out "

This is, what I hope is, all the relevant code from the main routine.

$MEW = new-object system.management.ManagementEventWatcher(
"SELECT * FROM __InstanceCreationEvent
WHERE TargetInstance ISA 'Win32_NTLogEvent'
AND TargetInstance.LogFile = '$LogName'")
$MEW.Scope.Path = "\\$Machine\root\cimv2"
# Set timeout to 5 seconds so we can use [ctrl]C and/or expire
$MEW.Options.Timeout = [timespan]'0:0:5'

.... irrelevant stuff....

# Wait for an event if at end-of-log and caller wants more
records. Loop
# with timeout so timers can be processed and [ctrl]c works.
while ($start -lt $Max -and
$start -ge ($Log.Entries.Count + $Log.entries[0].Index)) {
# Timeouts throw whereas I simply want $null returned
if (&{$ErrorActionPreference = 'SilentlyContinue'
$MEW.WaitForNextEvent()}) {
# Refresh the log object in case messages have rolled off the
$Log = new-object system.diagnostics.eventlog($LogName,
elseif ($PTimer) {
# There have been no messages for 5 seconds, see if there are
timers to
# expire before waiting again.

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)