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 4 months, 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #39034
    Profile photo of IanBurnell

    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 ??

    Profile photo of Don Jones
    Don Jones

    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.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.