I'd like to create a list of COM port on my computer (COM port + description). My point is to create a COM port list in order to communicate with a switch using an USB/RS232 converter.
What I try so far :
Get-WMIObject Win32_SerialPort | Select-Object DeviceID,Description
But all the COM port does not appear (example: COM11 is missing)
another attempt :
[System.IO.Ports.SerialPort]::getportnames()
here the port I need is present but the description is missing. (example : COM11 is present but with no details)
For information about how to read from a serial port in an asynchronous manner in PowerShell V2, use the DataReceived event on the port object with the Register-ObjectEvent cmdlet.
Use the GetPortNames method to query the current computer for a list of valid serial port names. For example, you can use this method to determine whether COM1 and COM2 are valid serial ports for the current computer. The port names are obtained from the system registry (for example, HKEY_LOCAL_MACHINEHARDWAREDEVICEMAPSERIALCOMM).
As an Administrator, start a new POWERSHELL command-line prompt. List the current TCP connections. Here is the command output. List the open TCP ports. Here is the command output. In our example, we listed only TCP ports in the listening state. Optionally, use a filter to get only the desired columns.
The order of port names returned from GetPortNames is not specified. Use the GetPortNames method to query the current computer for a list of valid serial port names. For example, you can use this method to determine whether COM1 and COM2 are valid serial ports for the current computer.
The above answers seem to be for deprecated Powershell objects.
I was able to use this:
Get-CimInstance -Class Win32_SerialPort | Select-Object Name, Description, DeviceID
Remove | Select-Object Name, Description, DevideID
to inspect additional properties.
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 this:
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 this
Get-WmiObject -Query 'SELECT Name, Description from Win32_PnPEntity WHERE Name LIKE "com%"'
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 could do this for each port that comes back from getportnames(). You'll probably want to call the Dispose() method on each port and set $c1 to $null after you finish gathering info for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With