1

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 ?

M.Brbr
  • 149

1 Answers1

0

It appears that this question is a near enough duplicate to the question here: Where can I find logs on recent USB insertion in the Event Viewer?

DBADon
  • 503