Link to home
Start Free TrialLog in
Avatar of itsegroup1
itsegroup1

asked on

Running a powershell script from the Task Scheduler in Win7/64

I'm able to execute a powershell and script from the cmd prompt:

powershell.exe -noexit -file c:\utils\myscript.ps1

myscript.ps1 is a simple copy to a network drive:

copy -R c:\temp z:\tempbackup

Works fine from cmd... all the files are copied over.

But, when I try to make this a scheduled task in the Task Scheduler it just starts running an never completes. In the Task Scheduler I created a new task with this action:
Start a program
powershell -noexit -file c:\utils\myscript.ps1

I.e. the exact same command as from the cmd.

How can I get this to run?

Thanks!
Avatar of rockiroads
rockiroads
Flag of United States of America image

I don't know if the execution policy has anything to do with it since its a background task. Have a look here and try as a bat file http://www.searchmarked.com/windows/how-to-schedule-a-windows-powershell-script.php
Avatar of itsegroup1
itsegroup1

ASKER

Thanks rockiroads, but I already found this ref and made sure execution policy is set to allow script running. Also tried various combos of putting the powershell.exe command into a bat file without joy. I don't see why you'd have to run powershell.exe through a bat in any event. Seems like it should be able to be launched directly.
when u created the task, what userid did you use. did u use one with admin privileges? perhaps its a permission issue

looking at noexit it says not to close after running startup commands. http://technet.microsoft.com/en-us/library/dd315276.aspx
I am not sure exactly about that but does it work without -noexit?

I used an account with amdin privs.

I tried both with and without -noexit option with no joy...
Hiya, did u get anywhere with this? I couldnt find anything else to try. might be worth clicking on request attention to get a bump.
powershell -noexit -command "c:\utils\myscript.ps1"
ASKER CERTIFIED SOLUTION
Avatar of itsegroup1
itsegroup1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial