[Powershell]导出指定的定时计划任务

<#	
	.NOTES
	===========================================================================
	 Created with: 	Visual Studio 2019
	 Created on:   	2019/8/23 18:00
	 Created by:   	Allen.Cai
	 Organization: 	Allen.Cai
	 Filename:     	export.ps1
	===========================================================================
	.DESCRIPTION
		ERP job scheduled tasks export scripts.
#>

$CurrentDate = Get-Date
$LogFile = "D:\backup\Tasks\ExportScheduledTasks_$($CurrentDate.ToString("yyyyMMddHHmmss")).log"
Start-Transcript -Path $LogFile
$BackupPath = "D:\backup\Tasks"
$ScheduledTaskPathRoot = "\Microsoft\ERP\"
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
作者:VAllen
出处:http://www.cnblogs.com/vallen
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
唯有偏执者得以生存。
posted @ 2019-09-07 16:50  VAllen  阅读(393)  评论(0编辑  收藏  举报