Erase all previous process

Erase all previous process

roualin powershell_2 Erase all previous processWhen you create a scheduled task, sometimes and old task is still running or already launched even if the task is stopped. To stop all previous process, I created a little function 🙂 :

function stopprocess($processname){

$wpids=$null

$pids=$null

$a=(Get-WmiObject -class win32_process | where{$_.ProcessName -eq $processname})

$a|foreach-object{

$processid=$_.processid

$process=(Get-WmiObject -class win32_process | where{$_.ProcessID -eq $processid}).getowner()

$user=$process.user

If($user -eq “svc-one-mpmadmin”){

If($pids -eq $null){

$pids=$processid

}

If($processid -gt $pids){

$pids=$processid

}

$wpids+=”/” + $processid

}

}

$wpidslength=$wpids.length – 1

$wpids=$wpids.substring(1,$wpidslength)

$wpids.split(“/”)|

where{$_ -ne $pids}|

foreach-object{

Stop-Process -id $_

}

}

To use that function, just write :

stopprocess “ping.exe”

This function will stop all process based on the ProcessID. Only the latest PID will left.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site