当我搜索这个网站时,其他人建议使用像-NoNewWindow这样的选项,然而,这似乎没有帮助。
我正在编写一个安装SCCM的脚本。这是一个相当长的安装过程(大约5分钟),即使我有-Wait,它也会在脚本的其余部分继续执行。
Start-Process -FilePath C:\temp\SCCM_Client\ccmsetup.exe -ArgumentList SMSSITECODE=PCM -Wait
Write-Host "Verify SCCM client install after reboot"`r`n -ForegroundColor Green它运行ccmsetup.exe,大约5秒后,它继续到下一行。我检查了一下任务管理器,ccmsetup.exe显然还在运行。
所以你们认为我有问题是因为这是一个安装程序而不是一个程序?(如果我启动进程notepad.exe,这个命令就能正常工作;直到我关闭记事本,它才会继续运行)这是我能想到的唯一不同之处
谢谢你的帮助!
发布于 2018-05-18 03:00:52
我遇到了这个问题,ccmsetup.exe产生了另一个进程来完成这项工作。因此,它的行为符合预期,因为powershell产生的ccmsetup.exe已经完成。
为了解决这个问题,我的解决方案是监控ccmsetup日志中的退出代码。
类似于下面的内容。
$count = 1
$LogFilePath = 'C:\Windows\ccmsetup\Logs\ccmsetup.log'
do
{
Write-Output "Uninstalling Software Center - attempt $count"
Start-Process -FilePath C:\temp\SCCM_Client\ccmsetup.exe -ArgumentList SMSSITECODE=PCM
$count++
Start-Sleep 30
while ((Get-Content -Path $LogFilePath -Tail 1 | Select-String -Pattern "CcmSetup is exiting with return code" -SimpleMatch) -eq $null)
{
#Check every 10 seconds for an exit code
Start-Sleep 10
}
} until((Get-Content $LogFilePath -Tail 1 -Wait | Select-String -pattern "CcmSetup is exiting with return code 0" -SimpleMatch -Quiet) -or $count -gt 3) 我现在不在工作,所以不能访问代码的实际部分-明天我会尝试用我使用的最终版本来更新它。
需要Start-sleep 30来防止它过早地检查日志和使用旧的退出代码。
https://stackoverflow.com/questions/50395327
复制相似问题