I am a newbie to PowerShell. I am working with Windows 10/11. I have been looking for a way to remove hidden serial ports. These can be seen in Device Manager if “Show Hidden” is enabled.
I found this script online “removeGhosts.ps1”. It can be found at:
This script will list and delete the “hidden” devices. However, I want to be more selective with the delete, deleting only USB-RS232 dongles.
When I run the script, the results are put into a PS array. However, I cannot access the array with an index. I get the error:
“out-lineoutput : Object reference not set to an instance of an object”.
I watched several YouTube videos. They give examples by populating the array with strings and then accessing the strings with an index, aka: MyArray[1]. That seems to be a simpler case than what I have.
I read some forum entries that talk about this error but either it didn’t work in my situation or I did not understand it, probably the latter.
Using PowerShell ISE, here are some commands from my PowerShell session.
##############################
$Devices = .\removeGhosts.ps1 -listGhostDevicesOnly -narrowByClass Ports
NarrowByClass: Ports
List ghost devices without removal: True
Total ghost devices found : 114
Total filtered ghost devices found : 12
##############################
$Devices.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- -------- True True Object System.Array
##############################
$Devices.Count
16
##############################
$Devices.Length
16
##############################
$Devices.IsFixedSize
True
##############################
$Devices
FriendlyName HWID InstallState Class
Prolific USB-to-Serial Comm Port (COM6) USB\VID_067B&PID_2303&REV_0400 False Ports
Silicon Labs CP210x USB to UART Bridge (COM23) USB\VID_10C4&PID_EA60&REV_0100 False Ports
USB Serial Port (COM11) FTDIBUS\COMPORT&VID_0403&PID_6015 False Ports
USB Serial Port (COM12) FTDIBUS\COMPORT&VID_0403&PID_6015 False Ports
USB Serial Port (COM20) FTDIBUS\COMPORT&VID_0403&PID_6015 False Ports
USB Serial Port (COM21) FTDIBUS\COMPORT&VID_0403&PID_6015 False Ports
USB Serial Port (COM22) FTDIBUS\COMPORT&VID_0403&PID_6015 False Ports
USB Serial Port (COM4) FTDIBUS\COMPORT&VID_0403&PID_6015 False Ports
XDS110 Class Application/User UART (COM10) USB\VID_0451&PID_BEF3&REV_0100&MI_00 False Ports
XDS110 Class Application/User UART (COM13) USB\VID_0451&PID_BEF3&REV_0100&MI_00 False Ports
XDS110 Class Auxiliary Data Port (COM14) USB\VID_0451&PID_BEF3&REV_0100&MI_03 False Ports
XDS110 Class Auxiliary Data Port (COM9) USB\VID_0451&PID_BEF3&REV_0100&MI_03 False Ports
##############################
$Devices[1]
out-lineoutput : Object reference not set to an instance of an object.
+ CategoryInfo : NotSpecified: ( [out-lineoutput], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.OutLineOutputCommand
##############################
So, what I am hoping to do is iterate through the list to remove the “hidden” USB-to-RS232 serial ports. I do not want to remove the XDS110 units or any other device that might not be a USB/232 DB9 dongle. I guess I will have to search for: (“USB Serial Port”|Prolific|CP210x). Of course, I will have to expand that list as others become known. I think the first step is to be able to index through the array but I cannot figure it out.
Any help will be appreciated.