Scheduled Task to run powershell script via GPO(computer on a particular day)

Harish Parameswaran 46 Reputation points
2022-01-09T04:08:13.547+00:00

Hi Reader,

How to create a scheduled task to run a powershell script whether user is logged on or not during a specific time via GPO.

I have implemented it locally using the following settings(attached image), which prompts for the user account password while creating the scheduled task. And, the task executes perfectly.

163393-image.png

however, when i configure the same task using GPO, it doesn't apply the policy in the endpoint and it doesn't prompt for a user account password. But when i select "Run only when user is logged on" the task gets created via GPO but it doesn't perform the action.

Any recommendation would be appreciated.

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,453 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,740 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,115 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Kazuki Masuda 81 Reputation points
    2022-01-09T15:16:26.313+00:00

    Hi,

    If you'd like to set "Run whether user is logged on or not" at scheduled task's general tab, you need to set "NT AUTHORITY\SYSTEM" user. Please refer to related webpage below.

    gpo-issue-deploying-a-scheduled-task-running-as-system -> The only way I’ve found to work around this issue is to:

    1. Set the user as “NT AUTHORITY\SYSTEM” ~

    If you'd like to set "Run only when user is logged on" at scheduled task's general tab, it is ok to set any users such as Domain\Administrator. But you need to enable execution of PowerShell in each client PC in advance, or PowerShell script may be failed to execute.

    I hope this information will be of use to you.

    Best Regards, Zaamasu


  2. Limitless Technology 39,351 Reputation points
    2022-01-11T14:23:15.263+00:00

    Hi there,

    You can use PowerShell cmdlets to create schedule tasks that automate the PowerShell script. It involves following steps,

    -Define time for the scheduler
    -Set Actions to be performed during execution
    -Save scheduler

    New-SchdeuledTaskTrigger creates a scheduled task trigger object. Using this cmdlet, you can specify the starting time of a task or starting a task multiple times on a daily or weekly basis.

    $Time=New-ScheduledTaskTrigger -At 4.00PM -Once

    Here is a thread as well which discusses the same steps and you can try out some steps from this and see if that helps you to sort the Issue.
    https://learn.microsoft.com/en-us/answers/questions/609608/gmsa-scheduled-task-run-whether-user-is-logged-in.html

    --------------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer--