Reputation: 23
I am using the following PowerShell script to return a list of connected USB Devices to the host computer:
gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)} | Sort Manufacturer,Description,DeviceID |Ft -GroupBy Manufacturer Description,Service,DeviceID
I would like to filter the results based on the Description. For instance, I would like to return only the Descriptions that are LIKE 'HASP%'.
What is the correct syntax to accomplish this?
Upvotes: 0
Views: 403
Reputation: 10034
You can use the Where-Object
cmdlet with the -like
operator with *
as the wildcard.
Get-WMIObject Win32_USBControllerDevice |
ForEach-Object {[wmi]($_.Dependent)} |
Where-Object {$_.Description -like 'HASP*'} |
Sort-Object Manufacturer,Description,DeviceID |
Format-Table -GroupBy Manufacturer Description,Service,DeviceID
Also note that ?
and where
are built-in aliases for the Where-Object
cmdlet, since you are using other aliases in your question.
Upvotes: 3