R
R
Rampage14102021-07-01 13:53:27
PowerShell
Rampage1410, 2021-07-01 13:53:27

Delete certain Powershell lines?

Any output IDshnikov devices in the form:
class CimInstance
{
HardwareID =
[
HID \ VID_046D & PID_C050 & REV_2720
HID \ VID_046D & PID_C050
HID \ VID_046D & UP: 0001_U: 0002
HID_DEVICE_SYSTEM_MOUSE
...
]

}

class CimInstance
{
HardwareID =
[
HID \ VID_1A2C & PID_2124 & REV_0110 & MI_01 & Col01
HID \ VID_1A2C & PID_2124 & MI_01 & Col01
HID \ VID_1A2C & UP: 000C_U: 0001
HID_DEVICE_SYSTEM_CONSUMER
...
]
Leave only the first line after the "[" character,and delete everything else and so on for each device.
I've been struggling with this for two days now.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2021-07-01
@Rampage1410

It is necessary, upon receipt of the ID, to immediately select and write it, and not to parse the crooked text output.
Although it is possible - first remove the line break between [ and the next line, then leave only such lines, and then remove " [ "
but it's better to collect immediately like this

Get-PnpDevice |
 Where {$_.HardwareID -notmatch 'PRINTENUM*|ROOT*|SW*|ACPIAPIC*|MONITOR*'} |
 Foreach { $_.HardwareID | Select -first 1 }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question