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!
PowershellWindows 7

Avatar of undefined
Last Comment
itsegroup1

8/22/2022 - Mon
rockiroads

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

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?

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
itsegroup1

ASKER
I used an account with amdin privs.

I tried both with and without -noexit option with no joy...
rockiroads

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

powershell -noexit -command "c:\utils\myscript.ps1"
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
itsegroup1

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.