O-Xchange Notes from the Field!

Thursday, October 23, 2008

How to schedule a powershell script

How to Schedule a powershell script
Here is how you can schedule a Windows Powershell Script:
The first thing you need to do is make sure that Powershell is set to execute Powershell scripts,
instead of only allowing interactive commands to be run in the Powershell environment.

Type the following at the Powershell command prompt:

set-executionpolicy RemoteSigned

This will allow the system to run Powershell scripts that are created locally (Remote Powershell scripts that may be downloaded must be signed).
Once this is done, you can create your Powershell script using notepad. Just make sure you name the file with an extension of .ps1 .
Now to run the script outside of its Powershell environment you type a command similar to the following:

powershell -command "& script.ps1' "

Just put the above command into a .bat or .cmd file and schedule it like you would normally schedule a script to be run with Windows task scheduler.
Now you can enjoy the weekend!

No comments:

Post a Comment