我喜欢的写法:
ps SQLQueryStress |Stop-Process
#1.纯cmdlet命令 Get-Process -Name notepad | Stop-Process #2.cmdlet+遍历 Get-Process -Name notepad | foreach-object{$_.Kill()} #3.WMI 对象 + 遍历 + 对象方法 Get-WmiObject Win32_Process -Filter "name = 'notepad.exe'" | ForEach-Object{$_.Terminate() | Out-Null } #4.WMI 对象 + 遍历 + cmdlet方法 Get-WmiObject Win32_Process -Filter "name = 'notepad.exe'" | Invoke-WmiMethod -Name Terminate | Out-Null
转载来源:https://blog.csdn.net/HoKis/article/details/79007546/