how to check whether a port is being used or not in windows code example
Example 1: see what ports are in use
Get-Process -Id (Get-NetTCPConnection -LocalPort portNumber).OwningProcess
Example 2: cmd listening ports
C:\> netstat -a -b
Get-Process -Id (Get-NetTCPConnection -LocalPort portNumber).OwningProcess
C:\> netstat -a -b