Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a function similar to Debug Diagnostics Collector.

Where you can setup a performance (or any counter) trigger (eg. above 50% CPU over 50 seconds). Once condition of a trigger are meet I would like to run a PS1 script.

Has anyone ever done something similar?

share|improve this question
up vote 1 down vote accepted

not sure about the 'over 50 seconds' aspect, but you could poll to see if your CPU is over a certain limit.

Just a quick sketch in powershell...

# checks cpu threshold and runs script in $scriptName variable
function CPUthreshold
    # mandatory single variable in function for script name

    # cpu percentage limit
    $limit = 50

    # time to poll CPU limit in seconds
    $pollTimeSec = 60

    # check limit forever!
        # get the win32_processor object to get stats on the CPU
        $cpu =  Get-WmiObject win32_processor

        # check if the CPU is over our limit
        if ($cpu.LoadPercentage -gt $limit)
            # call your script here!
            & $scriptName

        # wait again until the next poll
        Start-Sleep -s $pollTimeSec

# call function with script name you want to run
CPUthreshold .\Hello-World.ps1

you could run this in a thread, or background the process as well on the machine you are interested in.

share|improve this answer
Yes you are correct. I could technically get a PS script to do the sampling. However, in our case we have decided on using Nagios. – Luke Jun 2 '14 at 11:29
yes I think that is a good idea. nagios and icinga are widely used for this use case. – son_of_fire Jun 3 '14 at 16:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.