Wednesday, September 12, 2018

POWERSHELL - How to close all windows of specified process

This example shows script for closing all processes of "iexplore".

List of these running processes:
Get-Process iexplore
Output could be:
Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName                                                                                                    
-------  ------    -----      ----- -----   ------     -- -----------                                                                                                    
    499      46    29208      58308   303     0,45  25512 iexplore                                                                                                       
    641      54    13280      31924   212     0,31  26804 iexplore   
Here is the script for killing of this running processes:
# get process (check if exists)

$process = Get-Process iexplore -ErrorAction SilentlyContinue

# kill it

if ( $process ) { 
   
    echo " -> process found..it will be killed.." 
    
    $process.Kill()
}
else { 
    echo " -> process not found.." 
}
Output:
-> process found..it will be killed..

No comments:

Post a Comment