0

Does anyone know the correct way to assign a Powershell script as a scheduled task?

I have the below syntax (where X:/ is another drive mapped as a share).

enter image description here

GurdeepS
  • 1,646
  • 5
  • 26
  • 33

3 Answers3

2

I always just put 'powershell.exe' in the 'Program/script:' textbox and the full path to the script in 'Add arguments (optional)'. That always works for me.

I would also use a UNC name instead of a mapped drive letter. Who know whether the user who runs the task knows about that drive letter.

Peter Hahndorf
  • 14,058
  • 3
  • 41
  • 58
1

I've had problems when running Powershell scripts using the Nagios windows client, NSClient++. The solution for me was to run the command as follows...

cmd /c echo "X:\Technet Scripts\updateWindows.ps1" | powershell.exe -Command -

I'm not saying this is the best or correct way for you to run your script from a scheduled task, but it may get it working for you.

Craig Dodd
  • 156
  • 1
  • 2
0

What you have seems to be correct. Is it not running at the scheduled time, or are you getting an error?

The "-file" parameter isn't really required since you're not running the script in an existing session, but it should still work fine.

You can read more about running powershell scripts here: http://technet.microsoft.com/en-us/library/ee176949.aspx#EBAA

Lambo Jayapalan
  • 195
  • 1
  • 3
  • 9