Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Problem: every time USB is plugged in, code inside -Action{} runs 6-7 times
Desired: I want to handle it only once when event is raised.

Example:
$query = "SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2"
Register-WMIEvent -Query $query -Action {Write-Host "USB Plugged In"} -SourceIdentifier "PluggedIn"

In this case I will get "USB Plugged In" written 6 times when I plug 1 usb once. Not sure why, but every time the event is raised multiple times. At least this is the case for USB. I want to respond to usb plug in event with 1 action and do it 1 time, not 6 times. Need help, thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 18-Oct-13 16:19pm    
I reproduced it: 6 in the case of one flash card (SCSI) and 8 in case of another (USB). Perhaps you need to get event and see what's in them, maybe you need to filter just one from the set...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900