I am following this answer, which contains

Register-WmiEvent -Class win32_VolumeChangeEvent -SourceIdentifier volumeChange


$newEvent = Wait-Event -SourceIdentifier volumeChange

This works when I insert or remove a USB flash drive. (I'm thinking it's because of VolumeChange) I would like to detect insertion or removal of any USB device though, not only drives. Is this possible? Thank you!

1 Answer 1


Yes it's possible, you have to use DeviceChangeEvent instead of VolumeChangeEvent :

Register-WmiEvent -Class win32_DeviceChangeEvent -SourceIdentifier deviceChange


$newEvent = Wait-Event -SourceIdentifier deviceChange

Note that the SourceIdentifier is just the name of event subscription so you can keep "volumeChange" if you prefer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .