title: Powershell: Set a Scheduled Task to run when user isn't logged in
body: <p>I have been using the <a href="http://technet.microsoft.com/en-us/library/jj649816.aspx" rel="noreferrer">Powershell Scheduled Task Cmdlets</a> to create a scheduled task on our servers.</p>
  <p>How do I elect to 'Run whether a user is logged in or not using this API?</p>
  <p>I've created <code>action</code>, <code>trigger</code>, <code>principal</code> and <code>settings</code> objects, and passed them to <code>Register-ScheduledTask</code>, as below:</p>
  <pre><code>$action = New-ScheduledTaskAction -Execute foo.exe -Argument &quot;bar baz&quot;
  $trigger = New-ScheduledTaskTrigger -Once -At $startTime -RepetitionInterval (New-TimeSpan -Minutes 1) -RepetitionDuration ([Timespan]::MaxValue)
  $principal = New-ScheduledTaskPrincipal -UserId &quot;$($env:USERDOMAIN)\$($env:USERNAME)&quot; -LogonType ServiceAccount
  $settings = New-ScheduledTaskSettingsSet -MultipleInstances Parallel
  
  Register-ScheduledTask -TaskName $taskName -TaskPath &quot;\my\path&quot; -Action $action -Trigger $trigger -Settings $settings -Principal $principal
  </code></pre>
  <p>When I create a scheduled task like this, it defaults to 'Run only when the user is logged on.</p>
  <p><a href="https://stackoverflow.com/questions/12770293/how-to-set-schedule-service-run-whether-user-is-logged-on-or-not-in-powershell">This question</a> shows how to do so using COM objects, and <a href="https://stackoverflow.com/questions/11190405/how-to-schedule-a-task-wether-the-user-is-logged-on-or-not-in-powershell">this one</a> using schtasks.exe, but how do I do it using the <code>*-ScheduledTask*</code> cmdlets?</p>