Created
July 19, 2021 15:36
-
-
Save aev-mambro2/29bc3092b1af001dbd3d271d73172340 to your computer and use it in GitHub Desktop.
export-scheduled-tasks-from-remote-server-to-local-folder-structure.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$servers = @{ | |
"netbui-server-name" = @("\task\scheduler\path\*"), | |
"other-netbui-server" = @( | |
"\task\scheduler\path1\*", | |
"\task\scheduler\path2\*", | |
) | |
} | |
$outputFolder = "C:\Users\Me\Documents\scheduled-task-exports\"; | |
foreach ($h in $servers.Keys) { | |
$c = New-CimSession -ComputerName $h; | |
foreach ($p in $servers[$h]) { | |
Write-Output "Host: $h"; | |
Write-Output "Task path: $p"; | |
Get-ScheduledTask -CimSession $c -TaskPath $p | foreach { | |
$outputPath = "$($outputFolder)\$($h)\$($_.TaskPath)"; | |
if (!(Test-Path $outputPath)) { | |
New-Item -Path $outputPath -ItemType Directory; | |
} | |
Export-ScheduledTask -CimSession $c -TaskName $_.TaskName -TaskPath $_.TaskPath | Out-File ( | |
Join-Path "$($outputPath)\" "$($_.TaskName).xml" | |
) -Force; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this Powershell script to export scheduled tasks from 1 or more remote Microsoft Windows servers and write each task to a file on your local computer.
Supply which servers to visit. For each server, supply all scheduled tasks paths to export. Path GLOB patterns are allowed.
Supply a local output folder. The script will attempt to create it if it does not yet exist.
The script will store each task in a folder structure aligned with its task scheduler path. It will create folders if they don't yet exist.
File contents is formatted as XML. Thus the files get named with the xml extension.
Existing files will be overwritten. It is advised to add a date to the local output folder.
After export, use the import script to migrate the tasks to a different server: https://gist.github.com/aev-mambro2/6a350d5944bf904fe943ca02cd8712d5