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!
itsegroup1Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
itsegroup1Connect With a Mentor Author Commented:
No joy. I will continue to look into this and update if I find an answer, though I have a workaround for what my script was supposed to do.
0
 
rockiroadsCommented:
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
0
 
itsegroup1Author Commented:
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.
0
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
rockiroadsCommented:
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?

0
 
itsegroup1Author Commented:
I used an account with amdin privs.

I tried both with and without -noexit option with no joy...
0
 
rockiroadsCommented:
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.
0
 
Blake_1Commented:
powershell -noexit -command "c:\utils\myscript.ps1"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.