Announcement

Collapse
No announcement yet.

Executing script every minute using scheduled task in Windows Server 2003

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Executing script every minute using scheduled task in Windows Server 2003

    Dear experts,

    I'd like to know if executing a powershell script can be scheduled every one minute through scheduled task in Windows Server 2003 using powershell 2.0 ?

    so far i can only create "Daily" not even hourly automated running task.

    Code:
    schtasks /CREATE /TN CheckHealthScript /TR "powershell.exe -noprofile -executionpolicy Unrestricted -file %public%\checkhealth.ps1" /IT /RL HIGHEST /SC DAILY
    can anyone help me please ?

    Cheers,

    JJ

  • #2
    Re: Executing script every minute using scheduled task in Windows Server 2003

    Originally posted by Albertwt View Post
    so far i can only create "Daily" not even hourly automated running task.
    Is there an error message you receive when you try to make hourly tasks? Or does it just not execute hourly? As per KB 814596, the schtasks.exe command on server 2003 can be told through the /SC and /MO switches to execute based on minutes, hours, days, weeks, months, once, onstart, onlogon and onidle.
    Wesley David
    LinkedIn | Careers 2.0
    -------------------------------
    Microsoft Certifications: MCSE 2003 | MCSA:Messaging 2003 | MCITP:EA, SA, EST | MCTS: a'plenty | MCDST
    Vendor Neutral Certifications: CWNA
    Blog: www.TheNubbyAdmin.com || Twitter: @Nonapeptide || GTalk, Reader and Google+: [email protected] || Skype: Wesley.Nonapeptide
    Goofy kitten avatar photo from Troy Snow: flickr.com/photos/troysnow/

    Comment


    • #3
      Re: Executing script every minute using scheduled task in Windows Server 2003

      Originally posted by Nonapeptide View Post
      Is there an error message you receive when you try to make hourly tasks? Or does it just not execute hourly? As per KB 814596, the schtasks.exe command on server 2003 can be told through the /SC and /MO switches to execute based on minutes, hours, days, weeks, months, once, onstart, onlogon and onidle.
      no i just couldn't see it to execute hourly on the SCHTask wizard, but anyway it works after I create it on hourly and then go down deeper on Advanced button

      Comment


      • #4
        Re: Executing script every minute using scheduled task in Windows Server 2003

        Why not placing the powershell script into a batch file and let it loop every minute?
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment


        • #5
          Re: Executing script every minute using scheduled task in Windows Server 2003

          Originally posted by Dumber View Post
          Why not placing the powershell script into a batch file and let it loop every minute?
          oh yes, that is also a good idea, but the problem is that I don't know how to do it >_< that is why I go with the following path:

          Scheduled task --> Batch script --> Powershell

          Comment


          • #6
            Re: Executing script every minute using scheduled task in Windows Server 2003

            Since I'm on a mac right now, I write something how you could do it...

            Batch
            Code:
            :StartPS
            powershell.exe -noprofile -executionpolicy Unrestricted -file %public%\checkhealth.ps1
            
            sleep 60
            goto StartPS
            Rems can probably make it much more cleaner and nicer and better but if you fire this batch just once it will loop infinity. Rems can probably some checks to see if the process is running...
            Marcel
            Technical Consultant
            Netherlands
            http://www.phetios.com
            http://blog.nessus.nl

            MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
            "No matter how secure, there is always the human factor."

            "Enjoy life today, tomorrow may never come."
            "If you're going through hell, keep going. ~Winston Churchill"

            Comment


            • #7
              Re: Executing script every minute using scheduled task in Windows Server 2003

              Originally posted by Dumber View Post
              Since I'm on a mac right now, I write something how you could do it...

              Batch
              Code:
              :StartPS
              powershell.exe -noprofile -executionpolicy Unrestricted -file %public%\checkhealth.ps1
              
              sleep 60
              goto StartPS
              Rems can probably make it much more cleaner and nicer and better but if you fire this batch just once it will loop infinity. Rems can probably some checks to see if the process is running...
              Thank you once again for the response, may I know what is rems ?

              ok if somehow i didn't put sleep 60 would that script be executed every seconds with no pause ?

              is that REM for comment in bat script ?

              Comment


              • #8
                Re: Executing script every minute using scheduled task in Windows Server 2003

                Rems is one of our Forum Moderators and a scripting GOD.
                Sleep.exe is just euhhmmm sleep, so waiting for an X number of seconds.
                If you don't have it you can download the resource kit from here:
                http://www.microsoft.com/downloads/d...DisplayLang=en
                Marcel
                Technical Consultant
                Netherlands
                http://www.phetios.com
                http://blog.nessus.nl

                MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
                "No matter how secure, there is always the human factor."

                "Enjoy life today, tomorrow may never come."
                "If you're going through hell, keep going. ~Winston Churchill"

                Comment


                • #9
                  Re: Executing script every minute using scheduled task in Windows Server 2003

                  ...maybe he means Rems the Mod:

                  http://forums.petri.com/member.php?u=2530

                  ...I am guessing he does :smile

                  Edit:

                  Lol ..Just before me!

                  Comment


                  • #10
                    Re: Executing script every minute using scheduled task in Windows Server 2003

                    Rems can make a script that can kill two stones with one bird.
                    Wesley David
                    LinkedIn | Careers 2.0
                    -------------------------------
                    Microsoft Certifications: MCSE 2003 | MCSA:Messaging 2003 | MCITP:EA, SA, EST | MCTS: a'plenty | MCDST
                    Vendor Neutral Certifications: CWNA
                    Blog: www.TheNubbyAdmin.com || Twitter: @Nonapeptide || GTalk, Reader and Google+: [email protected] || Skype: Wesley.Nonapeptide
                    Goofy kitten avatar photo from Troy Snow: flickr.com/photos/troysnow/

                    Comment


                    • #11
                      Re: Executing script every minute using scheduled task in Windows Server 2003

                      Originally posted by Dumber View Post
                      Why not placing the powershell script into a batch file and let it loop every minute?
                      Why not put the sleep and loop right into the Powershell script?

                      Code:
                      while($true) {
                      
                        # work goes here
                      
                        start-sleep -seconds 1
                      }
                      -vP

                      Comment


                      • #12
                        Re: Executing script every minute using scheduled task in Windows Server 2003

                        Originally posted by Nonapeptide View Post
                        Rems can make a script that can kill two stones with one bird.
                        lol, he must be very deadly in the scripting skills >_<

                        anyway this is my final script:
                        Code:
                        while (!(Test-Connection gateway -Quiet -Count 1)) {
                        	Get-WMIObject Win32_NetworkAdapter -Filter "NetConnectionID LIKE '%'" | %{
                        		netsh interface set interface "$($_.NetConnectionID)" DISABLED
                        		netsh interface set interface "$($_.NetConnectionID)" ENABLED
                        	}
                        	Send-MailMessage -to "[email protected]" -from "[email protected]" -subject "TS NIC problem recovery" -body "vNIC reset by powershell v2.0" -smtpServer mail.domain.com
                        }

                        Comment


                        • #13
                          Re: Executing script every minute using scheduled task in Windows Server 2003

                          Originally posted by vonPryz View Post
                          Why not put the sleep and loop right into the Powershell script?

                          -vP
                          Since I don't speak Poweshell yet
                          Marcel
                          Technical Consultant
                          Netherlands
                          http://www.phetios.com
                          http://blog.nessus.nl

                          MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
                          "No matter how secure, there is always the human factor."

                          "Enjoy life today, tomorrow may never come."
                          "If you're going through hell, keep going. ~Winston Churchill"

                          Comment


                          • #14
                            Re: Executing script every minute using scheduled task in Windows Server 2003

                            Originally posted by Dumber View Post
                            Since I don't speak Poweshell yet
                            That's easy enough to fix.

                            Code:
                            $user = Get-User -name "Dumber"
                            
                            while($user.skillset.contains("Powershell") -eq $false) {
                              $subject = Get-LanguageResources -name "Powershell"
                              
                              foreach($r in $subject.GetRelevantStuff()) {
                                $student.Study($r)
                                $student.Practice() -force
                              }
                            }
                            -vP

                            Comment


                            • #15
                              Re: Executing script every minute using scheduled task in Windows Server 2003

                              LOL
                              Marcel
                              Technical Consultant
                              Netherlands
                              http://www.phetios.com
                              http://blog.nessus.nl

                              MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
                              "No matter how secure, there is always the human factor."

                              "Enjoy life today, tomorrow may never come."
                              "If you're going through hell, keep going. ~Winston Churchill"

                              Comment

                              Working...
                              X