liveBook · Manning

New-ScheduledTaskAction

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

New-ScheduledTaskAction is a PowerShell cmdlet that creates an action specifying the executable and arguments for a scheduled task.

New-ScheduledTaskAction creates the action portion of a scheduled task. Supply the PowerShell executable through Execute, then pass the script path and script parameters as one Argument string. section 3.2.2

Build the action in three practical steps:

  • Set Execute to the PowerShell executable, not the .ps1 file. section 3.2.2
  • Construct Argument with -File, the script path, and any script parameters as a single string. section 3.2.2
  • Create the action with New-ScheduledTaskAction, then combine it with a trigger and Register-ScheduledTask. section 3.2.2

Daily log cleanup action

An action can launch PowerShell 7 to run Invoke-LogFileCleanup.ps1 with log, archive, prefix, and retention parameters. Build the argument string with single-quoted PowerShell strings containing double-quoted paths, then splat Execute and Argument into New-ScheduledTaskAction.

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Explains executable selection, single-string arguments, quoting, splatting, and integration with triggers and registration.
Examples
Uses a daily Invoke-LogFileCleanup.ps1 task with quoted paths and log-retention parameters.
What it assumes
Assumes PowerShell scripting familiarity while demonstrating executable paths, argument quoting, and task-component assembly.
What you can do after
Build scheduled-task actions that launch parameterized PowerShell scripts unattended.
How it connects
Connects actions to New-ScheduledTaskTrigger, Register-ScheduledTask, PowerShell scripts, and Task Scheduler permissions.

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.