I want to list and kill all processes belonging to a session of a particular process that is using a port. This should happen through a windows batch command that would accept a port number as input.
For example: Let us say a process PA is currently listening on port 8081. PA is running under the session S1 There are processes PB and PC belonging to same session as PA. PB and PC will be running on different ports(It is not important which ports they are running on)
The windows command/batch file should take 8081 as input and kill the processes PA, PB and PC.
Is this possible? Appreciate a little help on this as I am not really well versed in batch commands/scripting.
My Failed attempt:
(for /F "tokens=2" %%i in (for /f "tokens=5" %a in ('netstat -aon ^| findstr 8081') do tasklist /NH /FI "PID eq %a") do taskkill /NH /FI "SESSIONNAME eq %%i")