title: How do I run a PowerShell script when the computer starts?
body: <p>I have a PowerShell script that monitors an image folder. I need to find a way to automatically run this script after the computer starts.</p>
  
  <p>I already tried the following methods, but I couldn't get it working.</p>
  
  <ol>
  <li><p>Use <code>msconfig</code> and add the PowerShell script to startup, but I cannot find the PowerShell script on that list.</p></li>
  <li><p>Create a shortcut and drop it to startup folder. No luck.</p>
  
  <pre><code>%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -File "C:\Doc\Files\FileMonitor.ps1"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Doc\Files\FileMonitor.ps1"
  </code></pre>
  
  <p>Here's my PowerShell script:</p>
  
  <pre><code>$folder = "C:\\Doc\\Files"
  $dest = "C:\\Doc\\Files\\images"
  $filter = "*.jpg"
  
  $fsw = new-object System.IO.FileSystemWatcher $folder, $filter -Property @{
      IncludeSubDirectories=$false
      NotifyFilter = [System.IO.NotifyFilters]'FileName, LastWrite'
  }
  
  $onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
  
      Start-Sleep -s 10
      Move-Item -Path C:\Doc\Files\*.jpg C:\Doc\Files\images
  }
  </code></pre></li>
  <li><p>I also tried to add a basic task using <code>taskschd.msc</code>. It is still not working.</p>
  
  <p>Here's what I found, and maybe that will help to debug it.</p>
  
  <p>If I open up a PowerShell window and run the script there, it works. But if I run it in a command prompt,</p>
  
  <pre><code>powershell.exe -File "C:\Doc\Files\FileMonitor.ps1"
  </code></pre>
  
  <p>It will not work. I am not sure it's a permission problem or something else.</p>
  
  <p>BTW, I have PowerShell 3.0 installed, and if I type $host.version, it will show 3 there. But my powershell.exe seems like it is still v1.0.</p>
  
  <pre><code>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
  </code></pre></li>
  </ol>