title: Register-ScheduledTask : Access is denied. (HRESULT 0x80070005)
body: <p>I'm trying to create a new Windows Scheduler Task, which will run some sync job.
  The things are:</p>
  <ul>
  <li>I want to use a separated service account, not Administrator</li>
  <li>I want to run a job not to get tied with service account's password change. In Windows Scheduler Task it is a &quot;Do not store password&quot; check button (&quot;-LogonType S4U&quot; option below)</li>
  <li>Job should be created by Powershell as job creation should be automated</li>
  </ul>
  <p>I'm running commands below under local Administrator and get an error:</p>
  <pre><code>PS C:\Temp&gt; $TaskAction = New-ScheduledTaskAction -Execute &quot;cmd.exe&quot; -Argument &quot;&lt;ARGUMENTS&gt;&quot;
  PS C:\Temp&gt; $TaskSettingsSet = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Hours 3) -MultipleInstances IgnoreNew -DontStopIfGoingOnBatteries
  PS C:\Temp&gt; $TaskTrigger = New-ScheduledTaskTrigger -RandomDelay (New-TimeSpan -Minutes 40) -Weekly -DaysOfWeek Saturday -At 7:30am
  PS C:\Temp&gt; $TaskPrincipal = New-ScheduledTaskPrincipal -UserId &quot;&lt;SERVICE_USER&gt;&quot; -LogonType S4U
  PS C:\Temp&gt; Register-ScheduledTask -Action $TaskAction -Description &quot;&lt;DESC&gt;&quot; -Settings $TaskSettingsSet -Principal $TaskPrincipal -TaskName &quot;&lt;TASK_NAME&gt;&quot; -TaskPath &quot;\&quot; -Trigger $TaskTrigger
  Register-ScheduledTask : Access is denied.
  At line:1 char:1
  + Register-ScheduledTask -Action $TaskAction -Description &quot;&lt;DESC&gt;&quot;  ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : PermissionDenied: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-ScheduledTask], CimException
      + FullyQualifiedErrorId : HRESULT 0x80070005,Register-ScheduledTask
  </code></pre>
  <p>&lt;SERVICE_USER&gt; has been added to &quot;Log on as a batch job&quot; local policy.
  Permissions for C:\Windows\Tasks or C:\Windows\System32\Tasks set with iCACLS does not help.
  I've even added &lt;SERVICE_USER&gt; to local Administrators group - the same error.</p>
  <p>If I do everything via GUI - it asks me &lt;SERVICE_USER&gt; credentials and works fine.</p>
  <p>What permissions do I lack?</p>