toasterking of BS Corporation Terminus
11/15/2017 - 4:43 PM

USB mass storage WMI queries

USB mass storage WMI queries

; This gets all storage devices using WMI and then uses relevance to filter to just the ones whose PNPDeviceID start with "usbstor\" (and are thus USB storage devices), then counts the number of results.

number of string values whose (it as lowercase starts with "usbstor\") of selects "PNPDeviceID FROM Win32_DiskDrive" of wmi

; This does the same as the above using WMI query language instead of relevance, then returns the Model string of each rather than the PNPDeviceID and just passes the strings instead of doing the counting.  The result is an array of strings.
; The syntax is tricky because:
; - In a WMI query, a backslash has to be escaped with a backslash.
; - % is a wildcard in WMI, but in relevance, % precedes an ASCII character code, so to pass a literal % to WMI, you must type %25

string values of selects ("Model from Win32_DiskDrive where PNPDeviceID like 'usbstor\\%25'") of WMI

; This does the same as the above but concatenates the array into a single string.

concatenation ", " of string values of selects ("Model from Win32_DiskDrive where PNPDeviceID like 'usbstor\\%25'") of WMI