Announcement

Collapse
No announcement yet.

Trigger on event in folder

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

  • Trigger on event in folder

    Hello,

    I'm trying to find a way to run a powershell script when a txt file is created in a SPECIFIC folder. I have a PHP website which generates certain logs and I gather information in these logs with powershell later.

    Does anyone know how to do this?

    Shortly:
    txt file is generated and stored in c:\test.
    When there is a txt file in c:\test -> run script.ps1

  • #2
    Re: Trigger on event in folder

    And why did you post it in the Windows Server 2008, instead the Powershell forum?
    Reported for moving ...

    Sorin Solomon


    In order to succeed, your desire for success should be greater than your fear of failure.
    -

    Comment


    • #3
      Re: Trigger on event in folder

      Could just run a task in task scheduler that runs the script every x minutes.
      ** Remember to give credit where credit is due and leave reputation points where appropriate **

      Comment


      • #4
        Re: Trigger on event in folder

        As Wired suggested, you will need to schedule the script to check the existence of the file.
        I can suggest you to use the Test-Path function.
        Something like this:

        Code:
         $LogFileCreated=Test-Path -path c:\test\logfile.txt
         if ($LogFileCreated -eq "True") { run commands }

        Sorin Solomon


        In order to succeed, your desire for success should be greater than your fear of failure.
        -

        Comment


        • #5
          Re: Trigger on event in folder

          Originally posted by sorinso View Post
          And why did you post it in the Windows Server 2008, instead the powershell forum
          Reported for moving ...
          Im sorry maybe I should have been more clear in my post.

          I want to create a trigger in the server (NOT in powershell). Im running windows server 2008 r2 thats why I posted it there.
          The action when the triggered event accurs is that it runs a powershell script. Im just asking how to configure triggers in server 2008 r2, not in powershell. Can you move it back?
          Last edited by Chrisdo; 11th April 2011, 12:44.

          Comment


          • #6
            Re: Trigger on event in folder

            OK, you could create the trigger by enabling auditing, then auditing the file creation on the folder
            That would generate a security log event and, since it is 2K8, you can create tasks attached to the occurrence of specific events to run your script
            Tom Jones
            MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
            PhD, MSc, FIAP, MIITT
            IT Trainer / Consultant
            Ossian Ltd
            Scotland

            ** Remember to give credit where credit is due and leave reputation points where appropriate **

            Comment

            Working...
            X