By default, if you launch a Win32 process from PowerShell, control returns immediately to the PowerShell and doesn’t wait for the process to terminate.
We can use [diagnostics.process] to start a Window’s batch job (or application) and wait until the job finished/terminated:
$batfile = [diagnostics.process]::Start("D:\Demo\My_Script.bat")
$batfile.WaitForExit()
Then the Powershell script resumes with the next line.
How can I have powershell run the silent un-install first wait till it is finished then run the install? After researching I did the below which works, but the blank Notepad window pops up and I had to close it. I don’t want the user to get any notepad window when I deploy this to them, simply uninstall and then install thank you.
Get-WmiObject -Class Win32_Product | Where-Object {$.Name -eq “On-Screen Takeoff”} | foreach- object -process {$.Uninstall()}
Notepad.exe | Out-Null
$arguments=”/quiet” Start-Process “\davisconstruction.com\ROOT\Installs\OnCenter\OST\Testverion3906\ost3906.msi” $arguments