Continuous loop

Hello again,

I have created a task schedule to check DBA is always logged on. This is at 5 minute intervals. I am thinking a contiuous loop would work better and be less intensive. 



{{ $i ; $i++


I tried this loop but whenever i pass If parameters it fails.

Would love to hear some ideas?


  • Why not just do...

    while ($true)
        # do stuff here

  • really cant be that simple can it? really? now i feel shame.

    that will run constantly untill not true! ie DBA logged off, using wmi to see if explorer is alive for dba

    Genius. I owe you, although you make me feel like a fool at times like this :)

  • That's one of the problems with PowerShell -- it makes some things so easy as to be unbelievable.  To further complicate it, it's easy many different ways.

    Write-Verbose "I'm doing stuff here"
    Start-Sleep -Seconds 5
    } until ($false)



  • Yeah, I'm partial to:

    Do {
    } While ($true)

    I love this notation (or any of the above) when I absolutely MUST do something and keep trying until it works (though even then I will try to build in some kind of escape).  You can use the Break statement to then jump out of the loop and move on.

  • How do you check if DBA is logged on? Maybe there is way of getting a notification when DBA is not logged on (that is making it "push", not "pull").

    That would have several benefits over infinite loop (less resources consumed etc.)