this repo has no description
1param (
2 [int[]]$ports
3)
4
5foreach ($port in $ports) {
6
7 $foundProcesses = netstat -ano | findstr :$port
8 $activePortPattern = ":$port\s.+LISTENING\s+\d+$"
9
10 if ($foundProcesses | Select-String -Pattern $activePortPattern -Quiet) {
11 $matches = $foundProcesses | Select-String -Pattern $activePortPattern
12 $firstMatch = $matches.Matches.Get(0).Value
13
14 $pidNumber = [regex]::match($firstMatch, "\d+$").Value
15
16 taskkill /pid $pidNumber /f
17 } else {
18 echo "Process $port was not not found"
19 }
20}