powershell-批量导出Job

$CurrentDate = Get-Date
$LogFile = "D:\Job\ExportScheduledTasks_$($CurrentDate.ToString("yyyyMMddHHmmss")).log"  #导出过程日志的保存路径
Start-Transcript -Path $LogFile
$BackupPath = "D:\Job\"          #导出文件的保存路径
$ScheduledTaskPathRoot = "\NONEDI\"  #job的路径  以'/'开始
Write-Host "Start exporting of scheduled tasks."
Get-ScheduledTask -TaskPath $ScheduledTaskPathRoot | ForEach-Object {
	$taskPath = $_.TaskPath
	$taskName = $_.TaskName
	
	New-Item -ItemType "directory" -Path "$BackupPath$taskPath" -ErrorAction SilentlyContinue
	$taskInfo = Export-ScheduledTask -TaskName $taskName -TaskPath $taskPath
	$taskInfo | Out-File "$BackupPath$taskPath$taskName.xml"
}
Write-Host "Saved file $BackupPath$TaskFolder$TaskName.xml"
Stop-Transcript
posted @ 2021-04-25 09:34  JinweiChang  阅读(100)  评论(0编辑  收藏  举报