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

Need to invoke functions but can't escape from loop

$
0
0

I need to write a script to check a mailbox every 15 seconds for new mail. I've made some progress but thinking forwards I'm gonna want to run the script against multiple mailboxes. It's something like this:

Function CheckMail {

start timer
start loop
 Get-MessageTrackingLog -Recipients $mailbox -EventID RECEIVE -Start $start -End $end
    if $mailbox (not null){
        do some stuff
        set it back to null
      }
  sleep for 15 seconds

} # end function

Invoke function

So the script calls a function which runs an infinite loop checking a mailbox every 15 seconds. I want to check multiple mailboxes though and was thinking the same thing but different functions and just invoke them all in one go at the beginning but the first one would get stuck in it's loop. Then there's the fact that I can't use an array as the mailbox variable because I also want to change the number of seconds to wait on some mailboxes so that wouldn't be a constant.

Any ideas as to how to go about this?
Thanks in advance



Viewing all articles
Browse latest Browse all 21975

Trending Articles



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