powershell 结束进程的四种写法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/HoKis/article/details/79007546

powershell 结束进程的四种写法

简单记录一下powershell中结束进程的四种写法:

#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

==END==

猜你喜欢

转载自blog.csdn.net/HoKis/article/details/79007546