Scheduled task that doesn't start

40 views Asked by At

I've been having a problem for a few days, I wanted to make a scheduled task containing a PowerShell script to change the basic default applications on certain accounts in the AD and, also wanted it to apply only once per user so they could make their settings without it resetting at each startup.

So first I created an immediate task with the option "Apply once and do not reapply". Then fans Actions, set the Powershell.exe link with the argument "-ExecutionPolicy Bypass "C:\lien_Vers_le_Fichier.ps1"". The problem is that the task doesn't apply, so I redid the same manipulation but with a scheduled task and added a line in the code that if the script runs, it creates a . txt file (to check if it's running at least) and then again, the task doesn't apply and isn't in the "Task planner", by doing a "gpresult /scope computer /r" it's displayed but doesn't run, even worse the task doesn't even start because the .txt file hasn't been created.

I've tried in the "When running the task, use the following user account" tab, I first put "%logondomain% and %logousers%, then changed it to my account. I've tried removing the powershell scipte and just putting in an .XML file containing all the default applications. I've tried Actions -> start a program -> settings -> program/Scipt = Powershell.exe. Add arguments = -File "C:\path_to_the_script.ps1". I've tried changing all the parameters of the Immediate/Scheduled task but it doesn't work. I've tried creating a new GPO but it doesn't work

Best regards.

Théo

Here is a screenshot of the GPO configuration

UPDATE ; I found out that in the event viewer, my GPO dind't started because I have an error code "0x80070005 access denied"

I'm hoping someone can help me

1

There are 1 answers

0
ErkinD39 On

In your scheduled task include a cmd or .bat file which first executes "powershell.exe -command "set-executionpolicy -executionpolicy Bypass" then your ps1 file "powershell.exe -file <filename.ps1>" At the end of the batch process pls restore the executionpolicy to its original state such as "powershell.exe -command "set-executionpolicy -executionpolicy AllSigned"

If your script runs locally you may run the task with local system account and in the script you may use the current user profile or HKCU registry as per your request.

If your script runs across the network you may choose to run the scheduled task with "Network Service" builtin account or a specified domain user account. Pls chk highest privileges in the task.