Win32_Process examples–terminate process

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

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

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 comment