【发布时间】:2018-04-05 06:47:10
【问题描述】:
我正在尝试获取一组指令以等待进程完成后再开始,但我一直让变量尝试在之后直接运行。
我会尝试wait(),但我不知道扫描需要多长时间。
#Variables
$logPath = "C:\Users\Administrator\Desktop\log.txt"
$scanPath = "C:\Users\Administrator\Desktop\scan.txt"
$repairLog = "C:\Users\Administrator\Desktop\repair.txt"
$failLog = "C:\Users\Administrator\Desktop\fail.txt"
$computer = "SERVER2012"
$CBSFileLocation = "C:\Windows\Logs\CBS\CBS.log"
$date = Get-Date
$sevenDays = New-Object System.TimeSpan 7,0,0,0,0
$repair = "Repair"
$fail = "fail"
$then = $date.Subtract($sevenDays)
#Start of Code:
$EventLog = Get-EventLog -LogName System -ComputerName $computer -After $then -Before $date -EntryType Error | Out-File $logPath
Start-Job -Name SFC {Start-Process sfc /scannow}
#I want the wait/suspend here.
Wait-Job -Name SFC {
$ScanX = Get-Content $CBSFileLocation
$ScanX | Out-File $scanPath
Select-String -Path $scanPath -Pattern $repair | Out-File $repairLog
Select-String -Path $scanPath -Pattern $fail | Out-File $failLog
echo "Done!!"
}
【问题讨论】:
标签: powershell process wait jobs suspend