概述
希望调用一个接受参数的 Powershell 脚本,在后台运行每个作业,并向我显示详细的输出。
我遇到的问题
该脚本似乎正在运行,但我想通过在后台作业运行时流式传输结果来确定这一点。
代码
###StartServerUpdates.ps1 Script###
#get list of servers to update from text file and store in array
$servers=get-content c:\serverstoupdate.txt
#run all jobs, using multi-threading, in background
ForEach($server in $servers){
Start-Job -FilePath c:\cefcu_it\psscripts\PSPatch.ps1 -ArgumentList $server
}
#Wait for all jobs
Get-Job | Wait-Job
#Get all job results
Get-Job | Receive-Job
我目前看到的:
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
23 Job23 Running True localhost #patch server ...
25 Job25 Running True localhost #patch server ...
我想看到的:
Searching for approved updates ...
Update Found: Security Update for Windows Server 2003 (KB2807986)
Update Found: Windows Malicious Software Removal Tool - March 2013 (KB890830)
Download complete. Installing updates ...
The system must be rebooted to complete installation.
cscript exited on "myServer" with error code 3.
Reboot required...
Waiting for server to reboot (35)
Searching for approved updates ...
There are no updates to install.
cscript exited on "myServer" with error code 2.
Servername "myServer" is fully patched after 2 loops
我希望能够看到输出或将其存储在某处,以便我可以回顾以确保脚本运行并查看哪些服务器重新启动等。
结论:
过去,我运行脚本,它一次更新一个服务器,并给了我想要的输出,但是当我开始做更多服务器时 - 这个任务花费了太长时间,这就是我尝试使用后台的原因带有“开始工作”的工作。
谁能帮我解决这个问题,好吗?