Let's say we want to release port
8081 (and we do not want to restart our computer).
First, find the Process ID that is using the port.
The easy way:
Get-Process -Id (Get-NetTCPConnection -LocalPort 8081).OwningProcess
Usually that works. But, if the easy way indicates that
System is the owning process, then we need to see more detail with the hard way...
The hard way:
netsh http show servicestate view=requestq | Add-Content netsh.txt; notepad netsh.txt;
In the hard way, once
netsh.txt is open in Notepad, search for
8081 and make note of the associated Process IDs.
Second, stop the associated process.
Stop-Process -ID 66476
All done. The port will now be free. :-)
P.S. This utility might also be handy for the "Hard Way" scenario. https://docs.microsoft.com/en-us/sysinternals/downloads/tcpview