Help with variables and -match/-like/etc

Im trying to write a script that checks for certain usb devices entities. This is the script thus far

function Get-USB { <# .Synopsis Gets USB devices attached to the system .Description Uses WMI to get the USB Devices attached to the system .Example Get-USB .Example Get-USB | Group-Object Manufacturer .Parameter ComputerName The name of the computer to get the USB devices from #> param ($computerName = "localhost") Get-WmiObject Win32_USBControllerDevice -ComputerName $ComputerName ` -Impersonation Impersonate -Authentication PacketPrivacy | Foreach-Object { [Wmi]$_.Dependent } } $computers = Get-Content C:POSHDevice.txt foreach ($comp in $computers) { if(Test-Connection -ComputerName $comp -BufferSize 16 -count 1 -Quiet) { $USB = Get-USB -computerName $comp |select PNPDeviceID } if ($usb -match 'USBVID_0801&PID_0011*') { Write-host "This is a Device" } } 

Currently it is doing the get-usb command correctly and returning a list of usb devices but its not doing any of this code it seems like

if ($usb -match 'USBVID_801&PID_0011*') 

if i do $usb to see what it has in the varible it does have a list of devices and that VID/PID is in the list. What am i missing i feel like its something stupid easy

submitted by /u/aford89
[link] [comments]

Leave a Reply