Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-03
7
Medium Priority
?
749 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33600788
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
ID: 33600801
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
ID: 33601424
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:itsegroup1
ID: 33620166
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
ID: 33706615
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
ID: 33710890
powershell -noexit -command "c:\utils\myscript.ps1"
0
 

Accepted Solution

by:
itsegroup1 earned 0 total points
ID: 33895562
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

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

661 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