Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I found a script that can delete files over X days old and changed it a bit so that i will scan different network folders to see if there are files that are older than X days. Now when i run the script with PowerShell ISE the script is working fine and doing what it should do. Taking about 1h

Now when i try to schedule the script with Windows Taskscheduler, the task starts and completes 10s later but the script didnt run. So no files were deleted?

Scheduled Task setting:


Run task with account that has logon as batch priviledges

Run wether user is logged on or not

Run with highest priviledges


Daily run


Program/script: Run a program C:\windows\system32\windowspowershell\v1.0\powershell.exe

Arrgument: -File “C:\scripts\deletefiles.ps1"

Anybody has an idea what i'm doing wrong? Or why its not running the script?

The script can be found here

share|improve this question

1 Answer 1

You need to Set-ExecutionPolicy so that the account running the scheduled task is allowed to execute Powershell scripts.

Set-ExecutionPolicy -Scope LocalMachine Unrestricted

As per the help file for Set-ExecutionPolicy, a scope of LocalMachine sets the policy for all users of that computer. As opposed to if you just Set-ExecutionPolicy Unrestricted from your own user account, it only sets that policy for your own user account. Furthermore, there are also separate policies for 32bit and 64bit versions of Powershell.

And if Set-ExecutionPolicy -Scope LocalMachine Unrestricted is too much of a security compromise to you, you could set it just for that one user by logging in as that user and doing it, or executing a process under that user's security context and setting the policy for that user.

Edit: Oh, and well, this probably doesn't need to be said, but we can't know if the user you've assigned to this scheduled task has the permissions necessary to delete stuff from those UNC paths.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.