Solved

How to run Power Shell script on a web server (Windows 2008 R2)

Posted on 2014-12-16
7
179 Views
Last Modified: 2014-12-17
Hello,

I have a Power Shell Script that I need to run every 9 minutes.  
If I put it on a file share, how can I get the script to run every 9 minutes without using Windows Task Scheduler.
Is there a way to make it run by itself?

Windows Server 2008 R2
0
Comment
Question by:Rad1
  • 3
  • 3
7 Comments
 
LVL 57

Expert Comment

by:Cliff Galiher
ID: 40503724
Why can't you use task scheduler?  That's its job, just like cron on Unix. It is pretty core to the OS.
0
 

Author Comment

by:Rad1
ID: 40503741
Because I need it now.  At work will take me 3 weeks to get the task scheduler to be implemented.
0
 
LVL 57

Expert Comment

by:Cliff Galiher
ID: 40503772
Well firing off a script "now" is possible if WinRM is enabled. But the "repeat every 9 minutes" will require task scheduler. That's what it is there for. The only other way would be to deploy software that does what task scheduler does, and then you are in the same boat of not being able to do that "now" as it isn't core to the OS...it'd be a full software deployment.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:Rad1
ID: 40503917
What about creating a clock script and in the script, set a function to run every 9 minutes to run the Power Shell script.  Would that work?
0
 
LVL 57

Expert Comment

by:Cliff Galiher
ID: 40504068
Not well. Scripts don't handle waits well. They basically brute force it by either forcibly throwing idle commands at a processor, which will kill performance of other threads, or by going to sleep, which isn't exact as to when the processor will return to check on the thread. The execute won't necessarily at 9 minutes, but sometime thereafter. If it were that easy, there'd be no need for a task scheduler.
0
 
LVL 80

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 40504215
wrap your powershell script in the following
$sleeptime = 9 * 60
do {
add your script
start-sleep -seconds  $sleeptime
} while ( 1 -eq 1)
#this is an infinite loop
0
 

Author Closing Comment

by:Rad1
ID: 40505843
Excellent!!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…

790 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