Solved

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

Posted on 2014-12-16
7
182 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
[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 58

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 58

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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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 58

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 81

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

728 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