gmsa scheduled task - run whether user is logged on or not

howbs2002 106 Reputation points
2021-10-29T19:23:28.45+00:00

I have a large number of scheduled tasks on a MS 2016 server, and I need to change them all to run using a gMSA, instead of a standard account.

I tried running the following, which worked, but I cannot figure out how to keep "Run whether user is logged in or not" selected.

schtasks /change /TN \taskname /RU DOMAIN\gmsaAccountName /RP

Run with highest privileges stays checked, but "Run whether user is logged in or not" changes to "run only when user is logged on"

I can recreate the task in PowerShell, and the setting is correct, but I am trying to avoid having to recreate all my tasks again from scratch, if there is a way to just use the schtasks /change command instead.

Appreciate any guidance on this.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,091 Reputation points
    2021-10-29T20:10:56.763+00:00

    You need to create a new principal for the scheduled task. Something like this:

    $p = New-ScheduledTaskPrincipal -UserId DOMAIN\gmsaAccountName -LogonType Password
    Get-ScheduledTask <taskname>| 
        Set-ScheduledTask -Principal $p
    

0 additional answers

Sort by: Most helpful