title: Run only when user is logged on
body: <p>I'm creating a PowerShell script which maps a network drive and I want it to be run at every logon. The commands inside the script work (when I run the commands, it maps the network drive), but the scheduled task doesn't works. By saying "it doesn't work" is that the task doesn't launch at all.</p>
  
  <p>This is my script:</p>
  
  <pre><code>$trigger = New-JobTrigger -AtLogOn
  Register-ScheduledJob -Name "MountAxiSante20015" -Trigger $trigger -ScriptBlock {
      New-PSDrive -Name "S" -Root "\\SERVEUR\Axisante2000" -Persist -PSProvider FileSystem
  }
  </code></pre>
  
  <p>In the task scheduler, I can see the task. In the GUI, in the general tab, the radio button selected is "Run whether user is logged on or not" and that's the problem. I want the task launch only when user is logged on! If I select the radio button "Run only when user is logged on", the task works and is launched at the logon.</p>
  
  <p>So is there a possibility to check this radio button <em>"Run only when user is logged on"</em> with PowerShell when creating the task? I have already checked in other threads but I can't find a solution.</p>