# kill-port-18080.ps1 # 查找并杀掉占用18080端口的进程 $port = 18080 Write-Host "正在查找占用端口 $port 的进程..." -ForegroundColor Yellow $processes = netstat -ano | Select-String ":$port\s" | Select-String "LISTENING" if ($processes) { foreach ($line in $processes) { $processId = ($line -split '\s+')[-1] if ($processId -match '^\d+$') { $process = Get-Process -Id $processId -ErrorAction SilentlyContinue if ($process) { Write-Host "找到进程: PID=$processId, 名称=$($process.ProcessName)" -ForegroundColor Cyan Stop-Process -Id $processId -Force Write-Host "已杀掉进程 $processId" -ForegroundColor Green } } } Write-Host "端口 $port 已释放" -ForegroundColor Green } else { Write-Host "端口 $port 未被占用" -ForegroundColor Yellow }