Reputation: 63
When I search this site, others have suggested using options like -NoNewWindow However, that doesnt seem to help.
I am writing a script that installs SCCM. It is quite a long install (about 5 min) and even though I have the -Wait, it literally continues on throughout the remainder of the script.
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
It runs the ccmsetup.exe then after about 5 seconds or so, it continues on to the next line. I check task manager and ccmsetup.exe is CLEARLY still running.
So you guys think Im having a problem because this is an installer and not a program? (this command works just fine if I Start-process notepad.exe; it wont continue on until I close notepad) That's the only thing I can think of that's different
Thanks for any help!
Upvotes: 1
Views: 3595
Reputation: 1
My solution to this particular problem was to use SCCM to build a batch file that actually works and runs separately from SCCM. It's an utterly insane solution.. but welcome to coding, I guess.
Write-Output "MsiExec.exe /x{5974413A-8D95-4D64-B9EE-40DF28186445} /qn" | Out-File -Encoding ASCII -FilePath mcafee-removal.bat
Write-Output "MsiExec.exe /x{377DA1C7-79DE-4102-8DB7-5C2296A3E960} /qn" | Out-File -Encoding ASCII -FilePath mcafee-removal.bat -Append
Write-Output "MsiExec.exe /x{820D7600-089E-486B-860F-279B8119A893} /qn" | Out-File -Encoding ASCII -FilePath mcafee-removal.bat -Append
Write-Output "MsiExec.exe /x{B16DE18D-4D5D-45F8-92BD-8DC17225AFD8} /qn" | Out-File -Encoding ASCII -FilePath mcafee-removal.bat -Append
Write-Output """%programfiles%\McAfee\Agent\x86\frminst.exe"" /remove=agent /silent" | Out-File -Encoding ASCII -FilePath mcafee-removal.bat -Append
Start-Process -FilePath "cmd.exe" -ArgumentList '/c .\mcafee-removal.bat'
The batch file behaves exactly the way you'd expect it to. SCCM's weird C++ implementation of powershell parsing ... yeah, not so much.
Hope this helps someone someday.
Upvotes: -1
Reputation: 1192
I had this problem, ccmsetup.exe spawns another process which does the work. So it's behaving as expected because the ccmsetup.exe spawned by powershell has finished.
To get around this, my solution was to monitor the ccmsetup logs for an exit code.
Something like below.
$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)
I'm not in work at the moment, so don't have access to the actual portion of code - I'll try to update this tomorrow with the final version I used.
The Start-sleep 30
was required to prevent it checking the log prematurely and using an old exit code.
Upvotes: 3