Scheduled Tasks

Copper Contributor

Has anyone got Scheduled Tasks to actually work in the latest Windows Admin Center? I'm just trying to run a very simple Powershell script that cleans up files in one directory on our servers. This script and task ran fine for years on our 2016 servers. I'm following this article: https://techdirectarchive.com/2020/03/26/how-to-create-a-scheduled-task-with-windows-admin-center/. There's not much else info out there about using Scheduled Tasks in WAC.

 

Relevant task settings I have:

Triggers: Daily, at 11 PM

Actions: Start a Program

Command: c:\path\to\script.ps1

Arguments: c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Security: Use built-in account, SYSTEM

Stop task if it runs longer than 2 hours.

 

The status is always "task terminated by user". I'm assuming it's hitting the 2 hour limit. The script is just to clean up files older than 7 days in one directory, and currently there are only a couple files older than 7 days, so the script should run in seconds. I've made several tweaks to the task, but nothing has worked. I've checked event viewer and didn't see any helpful messages. The script runs fine via WAC Powershell, so I know nothing is wrong with it.

 

Any suggestions?

 

Thanks,

Todd

1 Reply

Figured this out on my own. These are the correct settings:

Command: c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Arguments: -ExecutionPolicy Bypass c:\path\to\script.ps1

 

You may not need the -ExecutionPolicy parameter. We use CIS Level 1-2 settings on our systems, so security is pretty locked down.

 

Todd