Created
June 3, 2024 19:05
-
-
Save IAmStoxe/cc084646b7c251a74a720976aa9a348a to your computer and use it in GitHub Desktop.
This script finds and terminates the process listening on specified port.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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