$AllSerial = [System.IO.Ports.SerialPort]::getportnames() $RemoveNonUSBSerial = Get-PnpDevice -FriendlyName '* (COM*' -Class 'Ports' | ?{$_.DeviceID -notmatch '^BTHENUM'} $FriendlyNames = ($RemoveNonUSBSerial.FriendlyName) -join '|' $USBComPorts = $AllSerial | ?{$FriendlyNames -match "\($_\)"}