Skip to content

Instantly share code, notes, and snippets.

@IAmStoxe
Created June 3, 2024 19:05
Show Gist options
  • Save IAmStoxe/cc084646b7c251a74a720976aa9a348a to your computer and use it in GitHub Desktop.
Save IAmStoxe/cc084646b7c251a74a720976aa9a348a to your computer and use it in GitHub Desktop.
This script finds and terminates the process listening on specified port.
# Find the process ID (PID) listening on port
$port = 3000
$processId = Get-NetTCPConnection -LocalPort $port | Select-Object -ExpandProperty OwningProcess
# Check if processId is found
if ($processId) {
# Kill the process with the found processId
Stop-Process -Id $processId -Force
Write-Output "Process with PID $processId listening on port 3000 has been terminated."
} else {
Write-Output "No process found listening on port 3000."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment