Win32_Process examples–terminate process

Terminating a running process is simply a case of calling the Terminate method:

function remove-proc{
param (
[string]$computername = $env:COMPUTERNAME,

Get-CimInstance -ClassName Win32_Process -ComputerName $computername -Filter “Name = ‘$processname'” |
Invoke-CimMethod -MethodName Terminate

This will terminate all instances of a given process.  If you want to be more selective then change the function to use the process id rather than the process name

This entry was posted in CIM, PowerShell and WMI, PowerShell V3, PowerShell v4. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s