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
