Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

3 Commits

Repository files navigation

SchedTaskDSL

Scheduled Tasks written in a DSL for ease-of-use.

Overview

This is a Powershell module that provides a DSL structure for creating Scheduled Tasks on a Windows server.

Structure

The structure of the DSL is laid out much like the GUI for creating a task, here is an example

ScheduledTask "SyncFolders" {
User = John.Smith
Description ="Syncronizes two folders w/ robocopy."Hidden=$false
Security -RunOnlyWhenLoggedOn -RunAlways -StorePassword {
Credential =Import-Clixml-Path C:\Cred.xml
}
Trigger -OnASchedule -Weekly -SyncTimezones {
StartTime = [DateTime]"11/21/2018 18:00:00"
Recurrence =2#Days/Weeks - Depending on use of -Daily or -Weekly
WeekDays ="Monday","Wednesday","Friday"
}
Trigger -OnASchedule -Monthly -SyncTimezones {
StartTime = [DateTime]"11/21/2018 18:00:00"
Recurrence =2#Days/Weeks - Depending on use of -Daily or -Weekly
Months ="January","April","July","October"
Weeks ="First","Fourth","Last"
WeekDays ="Monday","Wednesday","Friday"
}
Action Powershell {
ScriptPath ="C:\PSScripts\SyncFolder.ps1"
Arguments ="-Source 'C:\Source' -Destination 'C:\Destination' -Mirror:$true"
}
}

Security Keyword

The switches for the Security keyword are:

ValueDescription
RunWhenLoggedOnRun this task only when the user is logged into the machine.
RunAlwaysRun the task regardless if the user is logged in. (If the task is executing against remote resources, it will require a username and password to be stored, use `-StorePassword parameter, along with a credential object inside the scriptblock.)
StorePasswordStores the username/password to impersonate when the task executes. Allowing non-local resources to be used in the script (i.e. Make a call to a website/DB/Rest-API/etc..., perform PSRemoting execution, use WMI/CIM session on a remote system, You get the idea!)

Trigger Keyword

The switches for the Trigger keyword are:

ValueDescription
OnAScheduleRun the task at a scheduled interval. (Additional parameters include: -OneTime | -Daily | -Weekly | -Monthly and [ -SyncTimezones ] )
AtLogOnRun the task when a user logs into the system.
AtStartupRun the task when the system boots into Windows.
OnIdleRun the task during idle periods (TODO: Add more details to this trigger.)
OnEventRun the task when a specific event is logged in the event log.
OnCreateEditRun the task upon creation or modification of this task.
OnConnectionRun the task when any user or a specific user connects locally or from a remote system. ( Additional parameters include [ -AnyUser | -Username ] and [ -RemoteConnection | -LocalConnection ])
OnDisconnectRun the task when any user or a specific user disconnects locally or from a remote system. ( Additional parameters include [ -AnyUser | -Username ] and [ -RemoteConnection | -LocalConnection ])
OnLockRun the task when any user or a specific user locks their desktop. ( Additional parameters include [ -AnyUser | -Username ])
-OnUnlockRun the task when any user or a specific user unlocks their desktop. ( Additional parameters include [ -AnyUser | -Username ])

The parameters included in the scriptblock include:

KeyValuesTrigger (Switch)SwitchDescription
StartTimeAny valid [datetime]All TriggersAll switchesA time/date for the task to begin running.
Recurrence1-999-OnASchedule-Daily or -WeeklySpecifies the number of days or weeks for each recurrence. (TODO: Test upper bounds of this value.)
WeekDaysArray of strings: Sunday-Saturday-OnASchedule-Weekly or -MonthlyAn array of week days for the task to execute upon each recurrence. Example: Every 2 weeks, execute on Monday, Tuesday, and Wednesday.
MonthsArray of strings: January-December-OnASchedule-MonthlyAn array of months for the task to execute.
WeeksArray of strings: First-Fourth and Last-OnASchedule-MonthlyAn array of the week number for the task to execute.

Action

This keyword performs an action for the task.

The switches for the Action keyword are:

ValueDescription
PowershellExecutes a Powershell script. Expects a .ps1 file that can require parameters as arguments.
CmdExecutes a .bat or .vbs script.

About

A Powershell DSL for Windows Scheduled Tasks

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors