locked
Scheduled task for powershell script RRS feed

  • Question

  • 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."

    Monday, August 31, 2015 2:28 PM

Answers

  • 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. 


    Kevin Remde US DX - IT Pro Evangelism - Microsoft Corporation http://aka.ms/FullofIT http://twitter.com/kevinremde


    • Edited by Kevin Remde Monday, August 31, 2015 2:38 PM
    • Marked as answer by JGrover Monday, August 31, 2015 2:41 PM
    Monday, August 31, 2015 2:37 PM

All replies

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

    It may be a security/permission issue. 


    Kevin Remde US DX - IT Pro Evangelism - Microsoft Corporation http://aka.ms/FullofIT http://twitter.com/kevinremde

    Monday, August 31, 2015 2:33 PM
  • 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. 


    Kevin Remde US DX - IT Pro Evangelism - Microsoft Corporation http://aka.ms/FullofIT http://twitter.com/kevinremde


    • Edited by Kevin Remde Monday, August 31, 2015 2:38 PM
    • Marked as answer by JGrover Monday, August 31, 2015 2:41 PM
    Monday, August 31, 2015 2:37 PM
  • 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?

    Monday, August 31, 2015 2:39 PM
  • That did the trick.  Thanks!
    Monday, August 31, 2015 2:41 PM