How to get all processes under a session of a particular process that is using a port in Windows cmd
That's actually pretty easy in PowerShell:
# Get the process of the listening NetTCPConnection and the session ID of the process
$SessionId = (Get-Process -Id (Get-NetTCPConnection -State Listen -LocalPort 8081).OwningProcess).SessionId
# Get all processes from that session and stop them
Get-Process | Where-Object { $_.SessionId -eq $SessionId } |
Stop-Process -Force -Confirm:$false