Scheduled task for powershell script

I have a file server in which I'm trying to run a powershell script as a scheduled task each day. It does not appear to be working.

I can manually run the script using the syntax ./scriptname.ps1, however I can't get it to run using something like:

c:\windows\system32\windowspowershell\v1.0\powershell.exe d:\userdata\redirect.ps1

I've also tried this:

powershell -file "D:\userdata\redirect.ps1"

Neither of these work (just trying from the Run box or from a command prompt).  If I go into powershell and run ./redirect.ps1the script runs fine and does its thing.

In case anyone is wondering, this script goes through our userdata folders and denies Read access for admins to the desktop.ini file it puts in there so everyone's folder doesn't just show up as "Documents."

August 31st, 2015 10:32am

When you say it doesn't work.. do you get any sort of error?

It may be a security/permission issue. 

Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 10:36am

In your scheduled task, you should be able to just say PowerShell as the program/script.  Then in the arguments, put .\redirect.ps1.  Make sure the Start in (optional) box has the path to where the file is located (D:\userdata\).

Let us know if that answers the question. 

August 31st, 2015 10:41am

I get no output.  The only indication I have that it didn't work is that the permissions aren't changed.

I figure it's something in how I'm creating the task, as I've never created a task for a powershell script before.  When I follow instructions online (the second example above was one I found) it doesn't work even by running it from the Run dialog or the command prompt, so I wouldn't really expect it to run as a task, either.

The first syntax example was the exported task from my old Windows 2008 file server with Powershell installed.  Running this syntax worked in 2008:

c:\windows\system32\windowspowershell\v1.0\powershell.exe d:\userdata\redirect.ps1
I still have that old server online in a sandbox test environment and running that command from the Run: dialog works properly.  I'm figuring there's just something different I need to do given it's a newer OS (2012 R2) that has Powershell more fully integrated perhaps?

Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 10:42am

That did the trick.  Thanks!
August 31st, 2015 10:44am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics