liveBook · Manning

Export-ScheduledTask

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

Export-ScheduledTask is a PowerShell cmdlet that exports a Task Scheduler task as XML.

Export-ScheduledTask exports a Task Scheduler task as XML, allowing a tested scheduled job to be stored, shared, and recreated on another Windows computer. section 3.2.2

A practical export workflow:

  • Identify the task with its task name and task path. section 3.2.2
  • Pipe the cmdlet’s XML string to Out-File, preferably on a shared location. section 3.2.2
  • Import the XML with Register-ScheduledTask, supplying the task name explicitly. section 3.2.2

Export a task for reuse

Export the LogFileCleanup task from the PoSHAutomation folder and save it as \\srv01\PoSHAutomation\LogFileCleanup.xml. A receiving computer can read the XML and register the task. section 3.2.2

$Argument = '-File ' +
    '"C:\Scripts\Invoke-LogFileCleanup.ps1"' +
    ' -LogPath "L:\Logs\" -ZipPath "L:\Archives\"' +
    ' -ZipPrefix "LogArchive-" -NumberOfDays 30'
$Argument
-File "C:\Scripts\Invoke-LogFileCleanup.ps1" -LogPath "L:\Logs\" -ZipPath "L:
\Archives\" -ZipPrefix "LogArchive-" -NumberOfDays 30

Use the accompanying listing to inspect the scheduled task’s PowerShell action and arguments before exporting its definition. section 3.2.2

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

How deep it goes
Explains XML export, file storage, and re-registration, then extends the workflow to importing multiple files.
Examples
Uses the LogFileCleanup task, a network share, XML files, and a foreach import loop.
What it assumes
Assumes familiarity with PowerShell cmdlets and scheduled-task registration.
What you can do after
Operate scheduled-task deployment by exporting definitions and recreating them from XML.
How it connects
Connects Task Scheduler, Out-File, XML parsing, and Register-ScheduledTask.

Related concepts

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.