title: How can I run a PowerShell script after reboot?
body: <p>I have a powershell script that tails specifics logs. If there is no update to the logs within a specific time span, an alert is then sent to nagios (as this depicts that the service is no longer running). </p>
  
  <p>The powershell script works great when run manually, but my issue is that I want it to load up on reboot. I've tried creating a scheduled task that repeats itself every 5 minutes using the arguments '-noexit -file C::\script.ps1'. The problem is then that my script doesn't actually work when run as a scheduled task.</p>
  
  <p>The execution policy is set to Unrestricted, so the script runs, but the code doesn't execute and work like it does when manually run. </p>
  
  <p>FWIW, the code is:</p>
  
  <pre><code>function Write-EventlogCustom($msg) {
      Write-EventLog System -source System -eventid 12345 -message $msg
  }
  
  Get-Content -Path C:\test.log -Wait | % {Write-EventlogCustom $_}
  </code></pre>
  
  <p>So if I update test.log while the powershell script runs a scheduled task, the event log doesn't get updated. However, when I run this script manually, and update to test.log, it does appear in the event viewer. </p>
  
  <p>I'm hoping that a second set of eyes might find something that I may have missed?</p>