title: POWERSHELL: Create Task - RunLevel Highest Access Denied
body: <p>Good afternoon,</p>
  <p>I am trying to create a Task in Task Scheduler using a Powershell script.
  I need the task to be 'Run with Highest Privileges'.</p>
  <p>I am using the following code that I found and modified.  This code runs successfully.</p>
  <pre><code>$jobname = &quot;Recurring PowerShell Task 2&quot;
  $script =  '-File &quot;C:\Users\Paul\Documents\RSYNC\Get-LatestAppLog.ps1&quot; -name ' + '10001.QvdDeletionTest'
  $action = New-ScheduledTaskAction –Execute &quot;powershell.exe&quot; -Argument  &quot;$script&quot;
  $duration = ([timeSpan]::maxvalue)
  $repeat = (New-TimeSpan -hours 3)
  $trigger =New-ScheduledTaskTrigger -Daily -At 2:00pm
  
  $msg = &quot;Enter the username and password that will run the task&quot;; 
  $credential = $Host.UI.PromptForCredential(&quot;Task username and password&quot;,$msg,&quot;$env:userdomain\$env:username&quot;,$env:userdomain)
  $username = $credential.UserName
  $password = $credential.GetNetworkCredential().Password
  $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -RunOnlyIfNetworkAvailable -DontStopOnIdleEnd
  Register-ScheduledTask -TaskName $jobname -Action $action -Trigger $trigger -User $username -Password $password -Settings $settings
  </code></pre>
  <p>However, if I add in the <code>-RunLevel Highest</code> (which was originally part of the <code>Register-ScheduledTask </code> line from the code that I found), the process fails with &quot;Access is Denied&quot;</p>
  <p>The user credentials I am using are definitely an Administrator on the pc.  If I go into the Task that is created without the <code>-RunLevel Highest</code> and manually change it to 'Run with Highest Privileges' I use the same credentials and it sets the Run Level accordingly.</p>
  <p>Please can someone help me so that the script sets the Task to RunLevel Highest?</p>