How to confirm before stopping the process in PowerShell?

To get the consent from the user before stopping process or instance, -confirm parameter is used.


In the below example, we will stop notepad.exe process with –Id 4900 using –Confirm parameter.

PS C:\WINDOWS\system32> Stop-Process -Id 4900 -Confirm
Are you sure you want to perform this action?
Performing the operation "Stop-Process" on target "notepad (4900)".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):

Similarly, you can use the –Confirm parameter for stopping the process with Name.

PS C:\WINDOWS\system32> Stop-Process -Name Notepad -Confirm