Windows无人值守安装中如何同步监控日志并继续软件安装
解决方案
直接用Start-Process启动独立的PowerShell窗口运行日志监控命令,这样当前脚本不会被阻塞,能继续执行后续的安装操作。
核心命令示例
# 启动独立PowerShell窗口持续监控日志 Start-Process powershell.exe -ArgumentList "-NoExit", "-Command", "Get-Content 'C:\windows\setup\scripts\FirstLogon.log' -Wait" # 继续执行后续的winget/choco安装命令 winget install --id Microsoft.VisualStudioCode -e choco install googlechrome -y # 其他软件安装命令...
参数说明
-NoExit:让新的PowerShell窗口保持打开状态,不会因为监控命令启动后就自动关闭。-ArgumentList:将监控命令作为参数传递给新启动的PowerShell进程,实现独立运行。
优化版(带窗口标题)
如果需要快速识别监控窗口,可以给窗口设置标题:
Start-Process powershell.exe -ArgumentList "-NoExit", "-Command", "`$Host.UI.RawUI.WindowTitle='安装日志实时监控'; Get-Content 'C:\windows\setup\scripts\FirstLogon.log' -Wait" -WindowStyle Normal
内容的提问来源于stack exchange,提问作者Eric Chang
相关产品推荐
相关产品推荐

