如何在 PowerShell 中停止进程前进行确认?

powershellmicrosoft technologiessoftware & coding

要在停止进程或实例前获得用户的同意,请使用 -confirm 参数。

示例

在下面的示例中,我们将使用 -confirm 参数停止 ID 为 4900 的 notepad.exe 进程。

PS C:\WINDOWS\system32> Stop-Process -Id 4900 -Confirm
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"):

类似地,您可以使用 –Confirm 参数来停止带有 Name 的进程。

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

相关文章