forked from modelcontextprotocol/servers
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathstop.ps1
More file actions
26 lines (20 loc) · 843 Bytes
/
Copy pathstop.ps1
File metadata and controls
26 lines (20 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
param([int]$Port = 3000)
$lines = netstat -ano | Select-String ":$Port\s" | Select-String "LISTENING"
$pids = @()
foreach ($line in $lines) {
$parts = ($line -replace '\s+', ' ').ToString().Trim().Split(' ')
$processId = [int]$parts[-1]
if ($processId -gt 0) { $pids += $processId }
}
$pids = $pids | Select-Object -Unique
if ($pids.Count -eq 0) {
Write-Host "Khong co server nao dang chay tren port $Port" -ForegroundColor Yellow
exit 0
}
foreach ($processId in $pids) {
$proc = Get-Process -Id $processId -ErrorAction SilentlyContinue
$name = if ($proc) { $proc.ProcessName } else { "unknown" }
Write-Host "Dang tat PID $processId ($name)..." -ForegroundColor Yellow
Stop-Process -Id $processId -Force -ErrorAction SilentlyContinue
}
Write-Host "Da tat server tren port $Port" -ForegroundColor Green