IT tutorials
 
Windows
 

Windows Server 2008 : Creating and Running a PowerShell Script - Scheduling PowerShell Scripts

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/28/2013 1:47:01 AM

You can schedule PowerShell scripts through the Task Scheduler, but it is a little trickier than simple batch files. If you try to schedule the .ps1 file, Notepad opens the file instead of the script running.

As an example, imagine that you created the following script and named it c:\scripts\feedback.ps1:

$obj = new-object -comobject wscript.shell
$intButton = $obj.Popup("Your message",0,"Title", 0)

Tip

This script displays a popup dialog box similar to Figure 1, though you can change the title and message to anything desired. You can test your script from the command prompt (not the PowerShell prompt) by entering the following: powershell c:\scripts\feedback.ps1.

Figure 1. Dialog box created with PowerShell



You can use the following steps to schedule it with Task Scheduler.

StepsComments
1. Launch the Task Scheduler with administrative permissions.Click Start, type Schedule in the Start Search text box, right-click Task Scheduler, and then select Run As Administrator.
2. Select Task Scheduler Library. Click Create Basic Task.The Create Basic Task button is in the right pane.
3. Name the task Testing and click Next.This is just for testing but you could create a schedule for a live script and change the name to anything desired.
4. Select Daily and click Next.You can also choose to run it weekly, monthly, or any other available timeframe.
5. Accept the default daily schedule and click Next.You can modify this time.
6. Ensure Start a Program is selected and click Next.This allows you to locate an executable file, including a script.
7. Enter powershell in the Program/Script text box. Enter c:\scripts\feedback.ps1 in the Add Arguments text box. Click Next.This has the net effect of typing the following command from the command prompt:

powershell c:\scripts\feedback.ps1.

Your display should look similar to Figure 2.
8. Click Finish to create the task.This creates the script.
9. Select Task Scheduler Library. Locate the Testing task in Task Scheduler. Right-click it and select Run.The script runs and the message box displays. However, it doesn’t appear as the top window so you might have to look for it. Although this isn’t elegant for a message box, it does show how to make a PowerShell script run.
10. Close all the open windows.If desired, delete the test task you created.

Figure 2. Scheduling a PowerShell script with Task Scheduler

The previous procedure creates a noninteractive command-line prompt in the background while the script runs. You can also run the PowerShell script by creating a batch file to run the script. The batch file would use the following line:

powershell -noexit c:\scripts\feedback.ps1

The -noexit switch keeps the PowerShell window open after the script runs, but you can omit it to ensure that PowerShell closes after the script runs.

Tip

Although it is not a native feature, you can download a free copy of the specops tool that enables you to schedule scripts similar to how you can with the Task Scheduler but with a few more features. You can check it out here: http://technet.microsoft.com/en-us/library/ff730969.aspx.

 
Others
 
- Windows Server 2008 : Creating and Running a PowerShell Script - Running a Script Against Multiple Computers
- Windows Server 2012 : Preparing for deploying domain controllers (part 3) - Existing forest domain controller deployment
- Windows Server 2012 : Preparing for deploying domain controllers (part 2) - New forest domain controller deployment
- Windows Server 2012 : Preparing for deploying domain controllers (part 1) - AD DS deployment scenarios
- Windows Server 2012 : Windows PowerShell automation (part 2) - Disconnected sessions
- Windows Server 2012 : Windows PowerShell automation (part 1) - Background jobs, Scheduled jobs
- Windows 7 : Making and Ending a Dial-Up Connection
- Windows 7 : Configuring a Dial-Up Internet Connection (part 2) - Adjusting Dial-Up Connection Properties
- Windows 7 : Configuring a Dial-Up Internet Connection (part 1) - Creating a New Dial-Up Connection
- Windows 7 : Installing a Modem for Dial-Up Service
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us