I'm using the following line to uninstall office 2007 based on its Product ID
Start-Process C:\Windows\System32\msiexec.exe -ArgumentList "/uninstall {90120000-0030-0000-0000-0000000FF1CE}"
I'd like to force a reboot after the uninstall is complete however using -Wait or piping the results to Out-Null don't wait until the uninstall is complete before processing the next line which is a restart. I've also tried using cmd to uninstall but with the same result.
cmd /c "msiexec.exe /uninstall {90120000-0030-0000-0000-0000000FF1CE}"
Is there any way to force powershell to wait until the uninstall is complete before processing the Restart-Computer command? I was thinking possibly writing something that detects when the setup.exe process stops before proceeding to the restart?
In PowerShell, we can use the Start-Sleep cmdlet to suspend/pause/sleep/wait the activity in a script or session for the specified period of time. You can use it for many tasks, such as waiting for an operation to be completed or pausing before repeating an operation.
You just need to use New-Object to create a stopwatch! It's as easy as 1, 2, $stopWatch = New-Object -TypeName System. Diagnostics. Stopwatch !
Start-Sleep Usage To pause the script for 10 seconds, I'd just use Start-Sleep -Second 10 . If I want to get anal about things, I could also specify the time in milliseconds as Start-Sleep -Milliseconds 10000.
PowerShell Pause cmdlets are used to halt the script's execution for a certain period, wait for the user inputs to enter and then proceed with the execution, slow down the speed of the execution, or wait for another process or job to complete first and resume execution.
The simplest workaround: pipe the result. This will force a wait until the process is finished.
No need for start-process
or cmd
.
You could pipe to out-default
, out-file
, out-null
or out-host
, depending on how you want to handle the output. (If you don't care about the output, simply use out-null
.)
& msiexec.exe /uninstall "{90120000-0030-0000-0000-0000000FF1CE}" | Out-Null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With