Advertisements

How to Schedule a PowerShell Script to Auto Run On a Windows Server

-

|

Introduction

If you want your PowerShell script to auto run at specific intervals you need to schedule the PowerShell script with Windows task scheduler.

There are other tools you can use to schedule a PowerShell script to run at specified times but this guide demonstrates how to do this with the Windows task scheduler

I will use the PowerShell script shown below for demo on this guide. The script creates folders if the folder does not exist in the directory.

Schedule-a-PowerShell-Script-example
Advertisements


Time needed: 5 minutes.

To Schedule a PowerShell Script to auto on a Windows Server, follow the steps below:

  1. Open Windows Task Scheduler

    Type task scheduler into the search box. Then click Task Scheduler.

  2. Create a New Task

    Right-click Task Scheduler Library. Then select Create Task.

    Schedule a PowerShell Script

  3. Name the task and Enter an optional description

    On the general tab of the new task give the task a name using the name field. You may also describe the task using the description box.

    On the box labelled 3, be sure to select Run whether user is logged on or not. If you select the first option the scheduled PowerShell script will not run unless the user is logged on.

  4. Create a Trigger to Auto run the Scheduled PowerShell Script

    To do this, click the triggers tab. Then click New. The New Trigger window will open.

    On the Begin the task drop-down, ensure that On a schedule is selected. Then select whether you want to Schedule the PowerShell Script to run Daily, Weekly or Monthly.

    You may also wish to schedule the PowerShell script to repeat at specific interval. To do this, check the Repeat task every box. Then click the drop-down to select a period.

    Another very important configuration is the Stop task if it runs longer than setting. Check this box to automatically stop the scheduled task. You may also set an expiry date for the task. The task will stop running after the set date.

    When you finish configuring the trigger, click Ok.

    Schedule a PowerShell Script

  5. Schedule the PowerShell script using the Actions tab

    Click the Actions tab. Then click New. On the Action drop-down, ensure that Start a program is selected. Then type PowerShell.exe on the program/script field.

    Next, enter the -File followed by the full path to the script on the Add arguments (optional) field. Here is the command I typed in the Add arguments (optional) field:

    -File “C:\PS\schedule powershell example\Create-folders-from-text-file.ps1”

    When you finish click Ok. Then click Ok again. When you click Ok, the second time, you will be required to confirm your password.

    Schedule a PowerShell Script

  • On the Username field, use the format ComputerName\username or Domainname\Username.

When you finish, here is what the Actions tab will look like. Effectively, you are asking task scheduler to run this command –

PowerShell.exe -File "C:\PS\schedule powershell example\Create-folders-from-text-file.ps1"
To confirm that the powershell script will run as scheduled, right-click the task and select Run.

Conclusion

For your script to run you need to use the -File parameter of the PowerShell.exe command in the actions tab. This is the trick. Otherwise your script may not run.

I hope you found this guide helpful. To leave a comment, suggestion or ask a question use the “Leave a Reply” form at the end of this page.

Other Helpful Guides

Additional Resources and References


LEAVE A REPLY

Please enter your comment!
Please enter your name here

LATEST DEALS

Exclusive Student Offer_Save 10% on selected Surface devices

FEATURED POSTS

How to Change Administrator Name in Windows 10 (4 Methods)

How to Change Administrator Name in Windows 10

Introduction This guide demos how to change administrator name in Windows 10. There could be...
How to Setup WhatsApp Auto Reply in an Android Phone

How to Setup WhatsApp Auto Reply in an Android Phone

Introduction This guide demos how to setup Whatsapp auto reply in an Android phone. Steps...
How to Set Out of Office Auto Reply in Outlook, Outlook.com and Gmail

How to Set Out of Office Auto Reply in Outlook, Outlook.com and Gmail

Introduction This guide demos how to set out of office auto reply in Outlook, Outlook.com and Gmail.
How to Take Ownership of Folder in Windows 10

How to Take Ownership of Folder in Windows 10 (2 Methods)

Introduction This guide demos 2 methods to take ownership of folder in Windows 10. Options to...
How to Install Windows Server 2019 from USB

How to Install Windows Server 2019 from USB

Introduction This guide demos how to install Windows Server 2019 from USB. Steps to Install...

ADVERTISEMENTS

TRENDING POSTS

Remote Desktop Connection

Remote Desktop Connection an Internal Error Has Occurred [Fixed]

Introduction I recently received the error message "Remote Desktop Connection an Internal Error Has Occurred". It was strange because...

Find My Samsung: Register and Use Samsung Find my Mobile

Introduction Ever wondered how you could find your Samsung phone if you lost it? Find my Samsung or Samsung...
What is the Difference Between PowerShell and CMD?

Windows Powershell vs CMD: Differences and Similarities

Introduction This short guide compares Windows PowerShell vs CMD (Windows command prompt). I will cover the history and nature...
Spotify No Longer Supports this Version of Microsoft Edge

Spotify No Longer Supports this Version of Microsoft Edge [Fixed]

Introduction When you open Spotify web player on Microsoft Edge, you may receive the error message "Spotify No Longer...
Windows 10 Won't Boot

Windows 10 Won’t Boot With Black Screen? 3 Ways to Fix It

Why Won't Windows 10 Boot Up? If your Windows 10 stops with a black screen, the first question in...

BEST OF ITECHGUIDES

dns server not responding featured image

“DNS Server Not Responding” Error [Fixed]

What Could Cause "DNS Server Not Responding" Error Message? The error messages "DNS Server Not Responding" or "DNS...
windows 10 search featured

How to Fix Windows 10 Search If it Stops Working

Introduction Are you having troubles with Windows 10 search? Apparently, it is a fairly common problem with a number...

Powershell For Loop Explained: Syntax and Examples

Introduction "Powershell For Loop" (or Statement) is a construct that is used to run a command in a...

How to Format a New Hard Drive in Windows 10 (3 Methods)

Introduction This guide demos 3 methods to format new hard drive in Windows 10. Options...
we can t sign into your account

How to Fix “We Can’t Sign into Your Account” Error in Windows 10

Introduction You may receive "we can't sign into your account" error after upgrading to Windows 10. If this occurs...

RECENT POSTS

C:\G-Drive\Work Tools\Products Portal\1. New Business\2. Content Sites\1. iTechGuides.com\Posts\1. HOW TO\Microsoft\MS Office\Microsoft Word\how to add more rows to a table in word

How to Add More Rows to a Table in Word and Google Docs

Introduction This guide demos how to add more rows to a table in Word. It also has a...
How to Create a Bar Chart in Excel and Google Sheets

How to Create a Bar Chart in Excel and Google Sheets

Introduction This guide demos how to create a bar chart in Excel and Google Sheets. A bar chart is...
How to Change Administrator Name in Windows 10 (4 Methods)

How to Change Administrator Name in Windows 10

Introduction This guide demos how to change administrator name in Windows 10. There could be...
How to Create a Pie Chart in Excel and Google Sheets

How to Create a Pie Chart in Excel and Google Sheets

Introduction This guide demos how to create a pie chart in Excel and Google Sheets. A pie chart is...

iTechGuides’ Top 10 Online Games

The gaming world is getting bigger day by day. Many people are getting engaged to play online games worldwide.

How to Open Local Security Policy in Windows 10 (5 Methods)

Introduction This guide demos how to open local security policy in Windows 10. Options to...

How to Change Network from Public to Private in Windows 10

Introduction This guide demos 2 methods to change network from public to private in Windows 10.
How to Disable Touchpad in Windows 10 for Dell or HP Laptop

How to Disable Touchpad in Windows 10 for Dell or HP Laptop

Introduction This guide demos how to Disable Touchpad in Windows 10 for a Dell or HP laptop.

How to Change Account Picture in Windows 10 (2 Methods)

Introduction This guide demos 2 methods to change account picture in Windows 10. Windows 10...
How to Create Xbox Live Account

How to Create Xbox Live Account (2 Methods)

Introduction This guide demos 2 methods to create Xbox Live account. Options to Create Xbox...

ADVERTISEMENTS

MUST READ

powershell get ad group members

PowerShell Script to Get Active Directory Group Members

Introduction This guide is a hands-on step by step showing how to write a Powershell script to Get AD...
Hot to Fix "DNS Address Could not be Found" in Windows 10

Hot to Fix “DNS Address Could not be Found” in Windows 10

Introduction If you receive the error message "DNS address could not be found" it may be caused by one...
Chrome ADMX

How to Download and Install Google Chrome Administrative Template

Introduction To configure Google Chrome settings via Group Policy you require Chrome ADMX. However, as you would expect by...
RAID 3 (Redundant Array of Independent Disks) Explained

RAID 3 (Redundant Array of Independent Disks) Explained

What is RAID 3? RAID 3 is a RAID implementation that uses striping with a dedicated parity disk....
windows server 2016 black screen after login

How to Fix Windows Server 2016 Black Screen After Login

Introduction A number of users have reported Windows Server 2016 black screen after login. The black screen happens:

LATEST DEALS

Exclusive Student Offer_Save 10% on selected Surface devices

By using this website you agree to accept our Privacy Policy and Terms & Conditions