tangled
alpha
login
or
join now
biscui.tech
/
dotfiles
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
feat: added kill-port script
biscui.tech
2 years ago
e07b3eb6
43edb280
+20
1 changed file
expand all
collapse all
unified
split
scripts
kill-port.ps1
+20
scripts/kill-port.ps1
···
1
1
+
param (
2
2
+
[int[]]$ports
3
3
+
)
4
4
+
5
5
+
foreach ($port in $ports) {
6
6
+
7
7
+
$foundProcesses = netstat -ano | findstr :$port
8
8
+
$activePortPattern = ":$port\s.+LISTENING\s+\d+$"
9
9
+
10
10
+
if ($foundProcesses | Select-String -Pattern $activePortPattern -Quiet) {
11
11
+
$matches = $foundProcesses | Select-String -Pattern $activePortPattern
12
12
+
$firstMatch = $matches.Matches.Get(0).Value
13
13
+
14
14
+
$pidNumber = [regex]::match($firstMatch, "\d+$").Value
15
15
+
16
16
+
taskkill /pid $pidNumber /f
17
17
+
} else {
18
18
+
echo "Process $port was not not found"
19
19
+
}
20
20
+
}