Step 1:

Open up cmd.exe (note: you may need to run it as an administrator, but this isn't always necessary), then run the below command:

netstat -ano | findstr :<PORT>

(Replace <PORT> with the port number you want, but keep the colon)

The area circled in red shows the PID (process identifier). Locate the PID of the process that's using the port you want.

Step 2:

Next, run the following command:

taskkill /PID <PID> /F

(No colon this time)

Lastly, you can check whether the operation succeeded or not by re-running the command in "Step 1". If it was successful you shouldn't see any more search results for that port number.

Answer from KavinduWije on Stack Overflow
🌐
Dzhavat Ushev
dzhavat.github.io › 2020 › 04 › 09 › powershell-script-to-kill-a-process-on-windows.html
PowerShell script to kill a process on Windows | Dzhavat Ushev
Note: To try it yourself, save it in a file called kill-port.ps1 and run it from PowerShell, passing a port number, e.g. ./kill-port.ps1 8080. Remember to use a port of a process you’ve started.
🌐
DEV Community
dev.to › dutchskull › how-to-kill-a-process-binding-to-a-specific-port-in-powershell-lh
How to Kill a Process Binding to a Specific Port in PowerShell - DEV Community
June 20, 2024 - We will use Get-NetTCPConnection to find the process ID (PID) using the port and Stop-Process to terminate the process. We will create a function called Kill-PortProcess that takes a port number as a parameter and kills the process using that port.
Discussions

Are you able to exit FastAPI/uvicorn via ctrl+c in Powershell on Windows?
Its multithreaded application. When you do ctrl+c, you kill the main process, not the subprocesses running on different threads. That's why you are unable to quit just like that. Read on Signal Handling to learn more. More on reddit.com
🌐 r/learnpython
15
7
April 2, 2024
Is there script to close application what using 8080 port automatically?
May I politely suggest this is the wrong way to go about ithings? If you need to use both applications, then you can configure one of them to use an alternate port.. and there is pretty much always a way to configure the ports in use - particularly for an application using such a common one. Alternatively, if you no longer need the existing application, uninstallling, or at least disabling it is the way to go. Relying on the script means that you have your never actually solving the problem, just repeatedly working around it. Configuring the the software so that it doesn't conflict, or disabling one of them solves the issue for good, and you no longer need the script. More on reddit.com
🌐 r/PowerShell
16
0
December 1, 2021
Top answer
1 of 4
12

Is there any thing like a pipe or similar that I can use on Windows OS to run this command in one line?

Both cmd.exe and PowerShell support pipes from one command to another. In PowerShell something like (this should be on a single line on the command line, or use ` to escapte newlines in a script):

netstat -ano
 | select -skip 4 
 | % {_ -split ' {3,}'; New-Object 'PSObject' -Property @{Original=$_;Fields=$a}} 
 | ? {$_.Fields[1] -match '15120$'}
 | % {taskkill /F /PID $_.Fields[4] }

Where:

  • Select -skip 4 skips the first four header lines. (Select is short for Select-Object used to perform SQL SELECT like projects of objects.
  • % is short for Foreach-Object which performs a script block on each object ($_) in the pipeline and outputs the results of the script block to the pipeline. Here it is first breaking up the input into an array of fields and then creating a fresh object with two properties Original the string from netstat and Fields the array just created.
  • ? is short for Where-Object which filters based on the result of a script block. Here matching a regex at the end of the second field (all PowerShell containers a zero based).

(All tested except the last element: I don't want to start killing processes :-)).

In practice I would simplify this, eg. returning just 0 or the PID from the first foreach (which would be designed to ignore the headers) and filter on value not zero before calling taskkill. This would be quicker to type but harder to follow without knowing PowerShell.

2 of 4
3

Open command prompt and execute:

for /f "tokens=5" %a in ('netstat -aon | find "8080"') do taskkill /f /pid %a

If you want to do it in a batch file instead, replace %a with %%a and | with ^|.

If you just want to kill the one that is listening on that port append | find "LISTENING" at the end of the other find.

🌐
Reddit
reddit.com › r/powershell › is there a powershell way i can use to kill an open port, and maybe automate the process?
r/PowerShell on Reddit: Is there a powershell way I can use to kill an open port, and maybe automate the process?
October 4, 2019 -

I've been having an issue with my IDE, that it's keeping open a port sometimes when I think it's closed. I'd like to be able to kill it by just typing in something and the port number, and I was wondering if there was a way to set this up in Powershell?

🌐
Code4IT
code4it.dev › blog › kill-the-process-blocking-a-port-windows
How to kill a process running on a local port in Windows | Code4IT
January 16, 2024 - Then, you can use the taskkill command by specifying the PID, using the /PID flag, and adding the /F flag to force the killing of the process. ... We have killed the process related to the running application.
Find elsewhere
🌐
YouTube
youtube.com › shorts › n9Aj4r4JAiU
The fastest way to kill a port in Windows #windows #powershell #tips - YouTube
I have to do it for port 3000 every so often:```netstat -ano | findstr :3000taskkill /PID 123123 /F```Even better, a one liner:``` Stop-Process -Id (Get-NetT...
Published   November 18, 2024
🌐
Sabbirz
sabbirz.com › blog › how-to-identify-and-kill-a-process-using-a-specifi
How to Identify and Kill a Process Using a Specific Port on Windows and Ubuntu| Sabbirz | Blog
kill process kill pid kill port lsof ubuntu list processes · In this blogpost, I will explore how to identify and terminate a process that is using a specific port on a Windows system & Ubuntu. This can be particularly useful when you need to free up a port that is being occupied by an unwanted or unknown application. Open Command Prompt as Administrator: Press Win + X and select "Command Prompt (Admin)" or "Windows PowerShell ...
🌐
VPSMakers
vpsmakers.com › home › windows › how kill a process running on a port in windows?
How Kill A Process Running On A Port In Windows - VPSMakers
April 23, 2024 - Follow our step-by-step instructions ... PID you want to free up. step 3: Kill the Process: In this step, the taskkill command followed by the PID and F flag, forces the process to terminate....
🌐
DEV Community
dev.to › andrewallison › killing-processes-on-ports-with-windows-185j
Killing Processes on Ports With Windows - DEV Community
December 7, 2022 - I've had some major issues with the ports when using NestJs. It keeps locking it's self out of the port it's using. This article will show you how to kill them with out needing to reset the machine. Using a windows PowerShell terminal with elevated privilages.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.management › stop-process
Stop-Process (Microsoft.PowerShell.Management) - PowerShell | Microsoft Learn
By default, this cmdlet returns no output. When you use the PassThru parameter, this cmdlet returns a Process object representing the stopped process. PowerShell includes the following aliases for Stop-Process:
🌐
GitHub
gist.github.com › dbagley1 › 9cc94ff5252aa40dee685e6ff7c1a52d
Windows: Find & Kill Processes Running on Port using CMD / Powershell · GitHub
Get PIDs using netstat and findstr replace <PORT> with the port you're looking for. ... Kill processes using taskkill replace <PROCESS_ID> with the PID from the previous command.
🌐
Medium
senthilk979.medium.com › how-to-kill-the-process-currently-using-a-port-on-localhost-in-windows-6bfc0c6e9e0
How to kill the process currently using a port on localhost in Windows | by Senthil Kumar | Medium
March 13, 2020 - Now you can execute this command to kill after identifying the PID. In our case PID is 4572 ... You can see the termination success message after executing the above command with the right PID. That’s it. You can now start the application in the expected port as you want. ... P.S. Run the first command again to check if process is still available or not.
🌐
Linux Hint
linuxhint.com › kill-process-currently-using-port-localhost-windows
How to Kill the Process Currently Using a Port on localhost in Windows – Linux Hint
To kill the Windows process currently using a port on localhost, use the “npx kill-port 8000” command on Command Prompt. On Windows PowerShell, the “Get -process” command and the “Stop-process” command to find out and end the specified processes. Lastly, the CurrPorts tools can ...
🌐
Technipages
technipages.com › home › how to kill a process on a port on windows 11: 5 best ways
How to Kill a Process on a Port on Windows 11 - Technipages
May 3, 2023 - Then, copy and paste the following cmdlet on the PowerShell terminal: Get-Process -Id (Get-NetTCPConnection -LocalPort <port_number>).OwningProcess · On the above cmdlet, you must replace the <port_number> placeholder text with an actual port ...
🌐
Medium
medium.com › @amarpreetbhatia › stop-process-wont-die-killing-hidden-processes-by-port-in-windows-linux-de531f8fe0f7
Stop! Process Won’t Die? Killing Hidden Processes by Port in Windows & Linux | by Amarpreet Bhatia | Medium
February 10, 2024 - Make the script executable (chmod +x kill_port.sh) and run it with the port number (e.g., ./kill_port.sh 8080). Again, the script will locate and terminate the process, providing feedback on its success.
🌐
Codinhood
codinhood.com › snippets › windows › find-kill-process-port-windows
Find and Kill a Process on a Specific Port on Windows | Codinhood
November 30, 2025 - ... The last column is the PID (Process ID). In this example, the PID is 24922. Use taskkill with the /PID flag and /F to forcefully terminate the process. ... If you prefer PowerShell, you can use Get-NetTCPConnection to find the process and Stop-Process to kill it.
🌐
Sentry
sentry.io › sentry answers › windows › kill process using port in windows
Kill process using port in Windows | Sentry
The final number on both lines is the process ID (PID) of the process using port 8080. Using this PID, we can end the process with taskkill: ... The /PID flag indicates that we’re locating the task to kill by PID, and the /F flag will forcefully ...