Create Scheduled task - run as logged on user

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 6 months, 3 weeks ago.

  • Author
    Posts
  • #39034
    Profile photo of IanBurnell
    IanBurnell
    Participant

    I'm creating a Scheduled task from SCCM as follows
    $Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-NonInteractive -NoLogo -NoProfile -File '$env:windir\UserCustomisations.ps1'"
    $Trigger = New-ScheduledTaskTrigger -AtLogOn
    Register-ScheduledTask -Action $action -Trigger $trigger -TaskName 'CBC User Customisations' -Description 'Created by SCCM Build. Runs at logon under users own credential to run user specific customisations'

    This is fine BUT I want it to run under user context at logon time. I found an article about changing (manually) the run as to the "users" group and that appears to work, but what I can't do is to get that name into the Powershell cmd. I've tried saying -user 'Users' and 'Builtin\Users' but PS just throw up an error – I assume because its looking for a user rather than a group. Any thoughts ??

  • #39472
    Profile photo of Don Jones
    Don Jones
    Keymaster

    As near as I can tell, the PowerShell cmdlets just weren't coded with this capability. You might just try using good ol' SchTasks.exe. It'll run fine in PowerShell.

You must be logged in to reply to this topic.