title: Creating a scheduled task which uses a specific event log entry as a trigger
body: <p>I am trying to use PowerShell to create a scheduled task which uses a Windows event log as a trigger. When an event is put into the event log, this task is kicked off. The event I want to monitor is event ID 8001, screenshot below. </p>
  
  <p>I am using the .Net method in my script, as I couldn't find a way to do this with PowerShell natively. <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa382577%28v=vs.85%29.aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/windows/desktop/aa382577%28v=vs.85%29.aspx</a></p>
  
  <p>This screenshot is a snapshot of an example Scheduled Task which targets the same event in which I want to monitor. </p>
  
  <p><a href="https://i.stack.imgur.com/6h4op.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6h4op.png" alt="Scheduled Task "></a></p>
  
  <p>Here is my attempt so far.</p>
  
  <pre><code>$taskName = "MyRepetitiveTask"
  
  $Service = new-object -ComObject ("Schedule.Service")
  $Service.Connect()
  $RootFolder = $Service.GetFolder("\")
  $TaskDefinition = $Service.NewTask(0)
  $TaskDefinition.RegistrationInfo.Description = ''
  $TaskDefinition.Settings.Enabled = $true
  $TaskDefinition.Settings.AllowDemandStart = $true
  $Triggers = $TaskDefinition.Triggers
  $Trigger = $Triggers.Create(0) ## 0 is an event trigger
  $Trigger.Enabled = $true
  $TaskEndTime = [datetime]::Now.AddMinutes(30);$Trigger.EndBoundary = $TaskEndTime.ToString("yyyy-MM-dd'T'HH:mm:ss")
  $Trigger.Id = '8001'
  $Action = $TaskDefinition.Actions.Create(0)
  $Action.Path = 'PowerShell.exe'
  $action.Arguments = "$dropboxPath\request\Scripts\Hire\NetworkConnections\StartLTE-WiFi.ps1"
  $RootFolder.RegisterTaskDefinition($taskName, $TaskDefinition, 6, "System", $null, 5) | Out-Null
  </code></pre>