Windows: find a port’s owner and resolve conflicts safely
Use PowerShell to identify a TCP listener and its process before stopping an application or selecting another port.
For Windows with the NetTCPIP module. These queries inspect only this machine, using 3000 as an example. For UDP use Get-NetUDPEndpoint. Some process details require elevation.
1. Find the TCP listener
Filter for Listen so a remote connection is not mistaken for a local server. “No matching objects” can simply mean no listener was found; it does not guarantee a later bind will succeed.
Get-NetTCPConnection -LocalPort 3000 -State Listen |
Select-Object LocalAddress, LocalPort, State, OwningProcess2. Identify the owner
Check the path, start time and service manager to identify the application. Multiple results can reflect different addresses. A process name alone is not permission to terminate a database or system service.
Get-NetTCPConnection -LocalPort 3000 -State Listen |
Select-Object -ExpandProperty OwningProcess -Unique |
ForEach-Object { Get-Process -Id $_ }3. Stop gracefully or change configuration, then recheck
For your own development server, use Ctrl+C in its terminal. Stop managed services through their normal workflow. If the existing app must stay running, change the new app’s listener and its callbacks or proxy settings. Query again and verify startup; forced termination is not the default step.
Sources and review
Sources checked on: