Powershell – Show all available Serial COM ports

Here are some methods to list all your available COM ports.  It’s handy when you’re swapping USB to serial adapters!  Here’s a cmd batch version if you prefer: Batch – Show all available COM ports

Four different ways…

One:

# Using get-pnpdevice
$portList = get-pnpdevice -class Ports -ea 0
if ($portList) {
     foreach($device in $portList) {
          if ($device.Present) {
               Write-Host $device.Name "(Manufacturer:"$device.Manufacturer")"
          }
     }
}

Output:

USB Serial Port (COM4) (Manufacturer: FTDI )
USB Serial Port (COM6) (Manufacturer: Microsoft )

Two:

# Using Get-WmiObject
$portList = (Get-WmiObject -query "SELECT * FROM Win32_PnPEntity" | Where {$_.Name -Match "COM\d+"})
if ($portList) {
     foreach($device in $portList) {
          if ($device.Present) {
               Write-Host $device.Name "(Manufacturer:"$device.Manufacturer")"
          }
     }
}

Output:

Prolific USB-to-Serial Comm Port (COM4)
Prolific USB-to-Serial Comm Port (COM6)

Three:

# Using [System.IO.Ports.SerialPort]
[System.IO.Ports.SerialPort]::getportnames() 

Output:

COM4
COM6

Four:

# Using change (can be used in cmd.exe also)
change port /query

Output:

COM4 = \Device\ProlificSerial0
COM6 = \Device\ProlificSerial2

4 Replies to “Powershell – Show all available Serial COM ports”

Leave a Reply to Phuntsog Wangdus Cancel reply

Your email address will not be published. Required fields are marked *