I would like my Powershell script to detect when I plug in a usb device. I have set the GPOs to block the automatic installation of usb devices.
For now I am using this command to detect when a usb device is plugged in :
$query = SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE TargetInstance ISA 'Win32_LogicalDisk' AND TargetInstance.DriveYpe=23
Register-WmiEvent -Query $query -SourceIdentifier RemovableDiskDetection -Action {...}
But probably because the device isn't installed, the event is not detected and nothing happens. What sort of query should I use to detect when a usb device is plugged in even if the driver of the usb device are not yet installed on the machine ?