Skip to main content

Scheduled Tasks

This page groups the Task Scheduler lifecycle functions. For full and always-up-to-date details, use Get-Help <FunctionName> -Detailed (or -Examples).

Invoke-ScriptTaskLifecycle

Orchestrate create/update/remove flow for scheduled tasks through a single lifecycle entry point.

Syntax

Invoke-ScriptTaskLifecycle -RegisterTask -TaskName <String> -ScriptPath <String> [-TaskPath <String>]
[-TaskTime <String>] [-ScheduleType <Daily|Once>] [-Description <String>] [-PwshPath <String>]
[-WorkingDirectory <String>] [-ExecutionPolicy <String>] [-PromptForCredential]
[-DefaultUserName <String>] [-Credential <PSCredential>] [-Force] [-LogLocation <String>]

Invoke-ScriptTaskLifecycle -UnregisterTask -TaskName <String> [-TaskPath <String>] [-LogLocation <String>]

Parameters

ParameterTypeDescriptionRequiredDefault
RegisterTaskSwitchEnables register/update lifecycle mode.ConditionalFalse
UnregisterTaskSwitchEnables unregister lifecycle mode.ConditionalFalse
TaskNameStringScheduled task name.Yes-
TaskPathStringTask Scheduler folder path (for example \Nebula\).No\
ScriptPathStringScript file to execute when registering.Required for register-
TaskTimeStringTrigger time string used by lifecycle registration flow.No02:00
ScheduleTypeStringTrigger type (Daily or Once).NoDaily
DescriptionStringTask description text.NoNone
PwshPathStringPath to PowerShell executable.NoAuto-detect (pwsh.exe fallback path)
WorkingDirectoryStringWorking directory for task execution.NoNone
ExecutionPolicyStringExecution policy passed to PowerShell.NoBypass
PromptForCredentialSwitchPrompts for credentials when needed.NoFalse
DefaultUserNameStringDefault username used with credential prompting.No$Env:UserDomain\$Env:UserName
CredentialPSCredentialExplicit credentials for task principal.NoNone
ForceSwitchReplaces existing task when applicable.NoFalse
LogLocationStringLog path used for lifecycle diagnostics.NoNone

Example

Invoke-ScriptTaskLifecycle `
-RegisterTask `
-TaskName "Daily-InventorySync" `
-TaskPath "\Nebula\" `
-ScriptPath "C:\Ops\Inventory\Sync.ps1" `
-TaskTime "03:00" `
-ScheduleType Daily `
-Force

Register-ScriptScheduledTask

Create or update a scheduled task that runs a PowerShell script.

Syntax

Register-ScriptScheduledTask -TaskName <String> [-TaskPath <String>] [-Mode <Standard|Xml>] [-ScriptPath <String>]
[-PwshPath <String>] [-ScriptArguments <String>] [-WorkingDirectory <String>] [-ExecutionPolicy <String>]
[-StartTime <DateTime>] [-ScheduleType <Daily|Once>] [-RepetitionIntervalMinutes <Int>]
[-RepetitionDurationHours <Int>] [-TaskXml <String>] [-TaskXmlPath <String>] [-Description <String>]
[-Credential <PSCredential>] [-RunElevated] [-Force] [-LogLocation <String>]

Parameters

ParameterTypeDescriptionRequiredDefault
TaskNameStringScheduled task name.Yes-
TaskPathStringTask Scheduler folder path.No\
ModeStringRegistration mode (Standard or Xml).NoStandard
ScriptPathStringScript file path (used in Standard mode).Conditional-
PwshPathStringPath to pwsh.exe/powershell.exe.Nopwsh.exe
ScriptArgumentsStringExtra arguments passed to the script.NoNone
WorkingDirectoryStringWorking directory for the task action.NoScript parent folder
ExecutionPolicyStringExecution policy passed to PowerShell.NoBypass
StartTimeDateTimeTrigger start time (standard mode).NoNow + 5 minutes
ScheduleTypeStringSchedule type (Daily or Once).NoDaily
RepetitionIntervalMinutesIntRepetition interval in minutes.No0
RepetitionDurationHoursIntRepetition window duration in hours.No0
TaskXmlStringRaw task XML content (xml mode).ConditionalNone
TaskXmlPathStringPath to task XML file (xml mode).ConditionalNone
DescriptionStringTask description.NoNone
CredentialPSCredentialCredentials used for the task principal.NoNone
RunElevatedSwitchRuns task with highest available privileges.NoFalse
ForceSwitchReplaces existing task when present.NoFalse
LogLocationStringLog destination for registration operations.NoNone

Example

Register-ScriptScheduledTask `
-TaskName "Daily-InventorySync" `
-TaskPath "\Nebula\" `
-ScriptPath "C:\Ops\Inventory\Sync.ps1" `
-StartTime ((Get-Date).Date.AddHours(3)) `
-ScheduleType Daily `
-Force

Unregister-ScriptScheduledTask

Remove a scheduled task by name/path.

Syntax

Unregister-ScriptScheduledTask -TaskName <String> [-TaskPath <String>] [-LogLocation <String>]

Parameters

ParameterTypeDescriptionRequiredDefault
TaskNameStringName of the task to remove.Yes-
TaskPathStringTask Scheduler folder path.No\
LogLocationStringLog destination for removal operations.NoNone

Example

Unregister-ScriptScheduledTask `
-TaskName "Legacy-InventorySync" `
-TaskPath "\Nebula\" `