Monday, March 22, 2010

Killing a process consuming more memory using PowerShell

There would be performance issues coming up in a server where we find that the server memory is being consumed by unnecessary processes. In order to prevent its unnecessary memory consumption, We can use the below powershell script which shall kill the process that consumes 100000000 KB of memory.

$computer = "mymachine"

$a = Get-Process -ComputerName $computer
$objs = $a | where-object {$_.WorkingSet -gt 100000000}
$processes = $objs | select {$_.ProcessName}


$i = $processes.Count

for ($k = 0; $k -lt $i; $k++)


{


$obj=get-wmiobject -comp $computer -query "select * from win32_process where name=$processes[$k]"
$obj.Terminate()


}


 Hope this helps....

No comments:

Post a Comment