Sunday, October 5, 2014

Schedule PowerShell (.PS1 file) script in Windows Task Scheduler - Part 3

Back in old days I used to schedule DOS batch files a lot with windows task scheduler, same way we can schedule Powershell PS1 script. For example purpose I am using my earlier script here as a demo monitor ping latency and drops, (for parameters check the blog) I have copied script code in notepad and saved it as a PS1 extension at location c:\temp\capture-latency.ps1.

In this ps1 file in the last I added mentioned function and its parameter Computer (-c), Latency (-L), Hours (-H), Filename (F).

Open task scheduler. Right click Task Scheduler library and Create new task.



Here I have given what time this task will trigger, example 8:30 AM is a login time of all user and I want to capture details for next 30 min or 1 hours, This is the time when all users login onto Terminal Servers., and load get increased
Powershell (Program/Script) will be running with, and below parameters (Add arguments).
 

 -NoProfile -ExecutionPolicy unrestricted -File "C:\Temp\Capture-latency.ps1"

Once done and clicking on will ask for the user credentials by on what user behalf this task need to be run, you should know password for the same user.

You will see the task just you created.

After creating task it gave warning that user should be have permissions to log on as batch job, for this I added same user in Backup Operators group to ensure he will get correct rights.

As the below screenshot you can locate same settings in GPEDIT.MSC. (This is just a demo here there are other best ways to provide users this permission)

To test the job you can right click and Run it, you will see csv file generated under c:\temp\folder

You can end the task by right clicking job., and verify the CSV file, if you find it is successful, you are ready to wait for next schedule to start this job.

Powershell Ping multiple IP addresses
Capture ping Latency or drops results with powershell - Part1
Capture multiple IP Latency or drops results with powershell Test-Connection - Part 2
Schedule PowerShell (.PS1 file) script in Windows Task Scheduler - Part 3
Post a Comment