PowerShell

Register and Create Scheduled Jobs with PowerShell

Scheduled jobs do something based on a trigger. We are able to configure scheduled jobs with the graphical user interface or – from my point of view – much easier and faster with PowerShell. In this blog post I will give you an example on how you can quickly create a scheduled job for your PowerShell script.

Open PowerShell ISE or VS Code. Copy the code below into your session and edit it at as you like.

Notice: This example code creates a scheduled job with the name PingC and a script located at c:\temp. Furthermore, a trigger is used that begins instantly and repeats every 15 minutes indefinitely.

Register-ScheduledJob -Name PingDC -FilePath "C:\Temp\script.ps1" `
-Trigger (New-JobTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 15) `
-RepeatIndefinitely)

Thank you for reading this article.

Categories: PowerShell

Tagged as: , ,

2 replies »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.