任务计划和Powershell的开始工作 [英] Task Scheduling and Powershell's Start-Job
问题描述
当前,我尝试运行PowerShell脚本,该脚本以 Start-Job -name $ jobname -Scriptblock {... Code ...}; $ c $开始一些实例c>
Currently, I try to run a PowerShell-Script, which starts a few instances with Start-Job -name $jobname -Scriptblock { ... Code ...};
此PowerShell脚本应在Windows任务计划中每15分钟执行一次。我以最高特权运行此过程,而Power-Shell-Script完美启动-问题是:
由Start-Job执行的代码不起作用。
This PowerShell-Script should be executed every 15 minutes in the WIndows Task Schedule. I run this process with highest priviledges, and the Power-Shell-Script starts perfectly - the problem is: The Code, which is executed by Start-Job doesn't work.
我认为问题是开始作业不能与任务计划一起使用。
I think the problem is that the "Start-Job" can not work with the task schedule together.
您知道如何解决吗?
谢谢,SUT
推荐答案
如果脚本末尾没有任何控件,则一旦创建后台作业,Powershell将立即退出。因此,尝试添加以下控制代码:
If no any control at the end of script, Powershell will immediately exit once background job is created. So try to add below control code:
$runningJobs = Get-Job -State Running
while($runningJobs.Count -gt 0){
Start-Sleep -Seconds 1
$runningJobs = Get-Job -State Running
}
Write-Host "Done!" -ForegroundColor Red -BackgroundColor Black
这篇关于任务计划和Powershell的开始工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!