search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell | No Comment | 2,010 views | 24/05/2013 10:15

In this example, you can’t open notepad.exe more than once. New notepad.exe processes will be killed.

1
2
3
4
5
6
7
8
9
$ShouldProcess = $true
While ($ShouldProcess)
{
                $Processes = Get-Process -Name Notepad -EA SilentlyContinue
                if ($Processes.Count -gt "1")
                {
                Get-Process -Name Notepad | Sort-Object StartTime | Select-Object -Skip 1 | Stop-Process
                }
}

Also it’s possible to add delay between process kills.