同文件夹下放2个powershell脚本,start.ps1和updatejobst.ps1,将start排入任务计划。
start.ps1内容
#job启动是以管理员权限调用updatejobst.ps1脚本。
Start-Process PowerShell -Verb RunAs "-Command `"cd '$pwd'; & '.UpdateJOBst.ps1';`""
updatejobst.ps1内容
$tp="";
$st=(Get-Date).AddMinutes(5).ToString("HH:mm");
$sd=Get-Date -Format "MM/dd/yyyy";
$ru="daminuid";
$rp="mima";
$Subject="update job start time"
$MailTo="ssx.@126.com"
try {
$tfn=@();
Get-ScheduledTask -TaskPath $tp| Where-Object {$d=($_.TaskPath+$_.TaskName);$tfn+=$d }
foreach($i in $tfn)
{
SCHTASKS /change /tn $i /st $st /sd $sd /RU $ru /RP $rp
}
Send-MailMessage -From xx@126.com -To $MailTo -Subject $Subject -SmtpServer smtpip -Body "update job start time sucessful!" -Encoding utf7
}
catch{
Send-MailMessage -From xx@126.com -To $MailTo -Subject $Subject -SmtpServer smtpip -Body "FailedItem:$_.Exception.ItemName" -Encoding utf7
}