Solved

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

Posted on 2010-09-03
7
714 Views
Last Modified: 2012-05-10
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!
0
Comment
Question by:itsegroup1
  • 3
  • 3
7 Comments
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
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
 

Author Comment

by:itsegroup1
Comment Utility
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
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:itsegroup1
Comment Utility
I used an account with amdin privs.

I tried both with and without -noexit option with no joy...
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
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
 
LVL 5

Expert Comment

by:Blake_1
Comment Utility
powershell -noexit -command "c:\utils\myscript.ps1"
0
 

Accepted Solution

by:
itsegroup1 earned 0 total points
Comment Utility
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

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now