Scheduled Tasks

%3CLINGO-SUB%20id%3D%22lingo-sub-1443312%22%20slang%3D%22en-US%22%3EScheduled%20Tasks%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1443312%22%20slang%3D%22en-US%22%3E%3CP%3EHas%20anyone%20got%20Scheduled%20Tasks%20to%20actually%20work%20in%20the%20latest%20Windows%20Admin%20Center%3F%20I'm%20just%20trying%20to%20run%20a%20very%20simple%20Powershell%20script%20that%20cleans%20up%20files%20in%20one%20directory%20on%20our%20servers.%20This%20script%20and%20task%20ran%20fine%20for%20years%20on%20our%202016%20servers.%20I'm%20following%20this%20article%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechdirectarchive.com%2F2020%2F03%2F26%2Fhow-to-create-a-scheduled-task-with-windows-admin-center%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Ftechdirectarchive.com%2F2020%2F03%2F26%2Fhow-to-create-a-scheduled-task-with-windows-admin-center%2F%3C%2FA%3E.%20There's%20not%20much%20else%20info%20out%20there%20about%20using%20Scheduled%20Tasks%20in%20WAC.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERelevant%20task%20settings%20I%20have%3A%3C%2FP%3E%3CP%3ETriggers%3A%20Daily%2C%20at%2011%20PM%3C%2FP%3E%3CP%3EActions%3A%20Start%20a%20Program%3C%2FP%3E%3CP%3ECommand%3A%20c%3A%5Cpath%5Cto%5Cscript.ps1%3C%2FP%3E%3CP%3EArguments%3A%26nbsp%3Bc%3A%5CWindows%5CSystem32%5CWindowsPowerShell%5Cv1.0%5Cpowershell.exe%3C%2FP%3E%3CP%3ESecurity%3A%20Use%20built-in%20account%2C%20SYSTEM%3C%2FP%3E%3CP%3EStop%20task%20if%20it%20runs%20longer%20than%202%20hours.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20status%20is%20always%20%22task%20terminated%20by%20user%22.%20I'm%20assuming%20it's%20hitting%20the%202%20hour%20limit.%20The%20script%20is%20just%20to%20clean%20up%20files%20older%20than%207%20days%20in%20one%20directory%2C%20and%20currently%20there%20are%20only%20a%20couple%20files%20older%20than%207%20days%2C%20so%20the%20script%20should%20run%20in%20seconds.%20I've%20made%20several%20tweaks%20to%20the%20task%2C%20but%20nothing%20has%20worked.%20I've%20checked%20event%20viewer%20and%20didn't%20see%20any%20helpful%20messages.%20The%20script%20runs%20fine%20via%20WAC%20Powershell%2C%20so%20I%20know%20nothing%20is%20wrong%20with%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20suggestions%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3ETodd%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1481998%22%20slang%3D%22en-US%22%3ERe%3A%20Scheduled%20Tasks%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1481998%22%20slang%3D%22en-US%22%3E%3CP%3EFigured%20this%20out%20on%20my%20own.%20These%20are%20the%20correct%20settings%3A%3C%2FP%3E%3CP%3ECommand%3A%26nbsp%3B%3CSPAN%3Ec%3A%5CWindows%5CSystem32%5CWindowsPowerShell%5Cv1.0%5Cpowershell.exe%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EArguments%3A%20-ExecutionPolicy%20Bypass%26nbsp%3B%3CSPAN%3Ec%3A%5Cpath%5Cto%5Cscript.ps1%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20may%20not%20need%20the%20-ExecutionPolicy%20parameter.%20We%20use%20CIS%20Level%201-2%20settings%20on%20our%20systems%2C%20so%20security%20is%20pretty%20locked%20down.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETodd%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New 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
Highlighted

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