Is there a gentle way of stopping processes using Windows PowerShell?

powershell

Solution

Try this to simulate the user closing the app:

(Get-Process -Id 10024).CloseMainWindow()

Problem

I have to stop a browser from a PowerShell script, which I do by piping it into ``` Stop-Process -Force ``` However, this is very abrupt. When the browser is restarted, it detects that it didn't shut down cleanly, and tries to restart the previous session. Is there some way I can tell it to shut itself down gracefully? ("There are two ways we can do this ...")

Original source