Apr 272018
 
 April 27, 2018  Posted by at 5:00 am .NET Core, ASP  Add comments

I have a bad habit of using the NuGet Package Manager Console in Visual Studio as a PoSh CLI (which it sort of is), and today I ran ‘dotnet run’. And then I was unable to kill the session. The console was unresponsive, and so was the NuGet browser. Arghhh….ops. I restarted Visual Studio, and that got the console working again, but my port was taken and Kestrel spinning.

PowerShell has cmdlets for most things you could do in the good ol’ commandline, and there is one for working with TCP connection.

This will list all the connections:


Get-NetTCPConnection


and if you had some filtering with the parameters such as the port you can narrow down the result


Get-NetTCPConnection -Port 1106

The result is a list, and if you wrap the result in parenthesizes you can enumerate the items and pull out specific properties without piping+iteration


(Get-NetTCPConnection -LocalPort 1106).OwningProcess

This gave me the PID (process ID), and with that I could run


$rsult = (Get-NetTCPConnection -LocalPort 1106).OwningProcess[0]

Kill -Id $result

Voila. Process dead.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

What is 8 + 15 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)