Saturday, February 9, 2019

kill multiple process from Power Shell.

We face many time issue when we need to kill running multiple process on the windows environment.This power shell function will help you kill multiple process which you want to kill.

Function KillProcess($sProcessNameStr) 
{ 
    $sStringArray = $sProcessNameStr -split ","                                                              
    $sProcessName1 = @($sStringArray) 
    Foreach($sProcessName in $sProcessName1) 
        {  
            $sProcessName1 = [System.IO.Path]::GetFileNameWithoutExtension($sProcessName) 
            $sProcessName = Get-Process $sProcessName1 -ErrorAction SilentlyContinue 
            if($sProcessName -ne $null) 
              {  
                Stop-Process -ProcessName $sProcessName1 -ErrorAction SilentlyContinue 
              } 
         } 
} 
 
# E.g 
KillProcess "notepad.exe","iexplore.exe"
Note:-Please test script in your test environment before running in production directly.

No comments:

Post a Comment