Powershell Serial Port List + Description

I would like to create a list of COM port on my computer (COM port + description). I want to create a list of COM ports for communicating with the switch using a USB / RS232 converter.

What I'm trying so far:

Get-WMIObject Win32_SerialPort | Select-Object DeviceID,Description 

But the whole COM port does not appear (example: COM11 is missing)

another attempt:

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

there is a port that I need, but no description. (example: COM11 is present, but without any details)

+6
source share
2 answers

How about this?

 $c1 = new-object System.IO.Ports.SerialPort com1 $c1 BaseStream : BaudRate : 9600 BreakState : BytesToWrite : BytesToRead : CDHolding : CtsHolding : DataBits : 8 DiscardNull : False DsrHolding : DtrEnable : False Encoding : System.Text.ASCIIEncoding Handshake : None IsOpen : False NewLine : Parity : None ParityReplace : 63 PortName : com1 ReadBufferSize : 4096 ReadTimeout : -1 ReceivedBytesThreshold : 1 RtsEnable : False StopBits : One WriteBufferSize : 2048 WriteTimeout : -1 Site : Container : 

You can do this for each port that returns from getportnames (). You probably want to call the Dispose () method on each port and set $ c1 to $ null after you finish collecting information for it.

+3
source

did this:

https://www.google.com/search?q=powershell+get+available+com+ports&gws_rd=ssl

found this:

http://empegbbs.com/ubbthreads.php/topics/362862/Windows_command_to_quickly_lis

which led to the following:

https://github.com/todbot/usbSearch/blob/master/listComPorts.vbs

so I adapted it to this:

 Get-WmiObject Win32_PnPEntity -Filter "Name LIKE 'com%'" | Where Name -match 'COM\d+' 

or

 Get-WmiObject -Query 'SELECT Name, Description from Win32_PnPEntity WHERE Name LIKE "com%"' 
+2
source

Source: https://habr.com/ru/post/971055/


All Articles