Also… it would help if you told us what did not work about it, though i’m guessing it just doesn’t do anything. Nontheless, please avoid blanketed statements and provide detail so people can better assist. Don’t be afraid to explain in detail what you actually are doing with your code; don’t make assumptions about what your audience knows.
Lastly, always provide the expected output/behavior and actual output/behavior in simple terms so people know what you are trying to accomplish.
I’ve not worked that much with this type of stuff, but if you are indeed trying to run a script when a USB device is connected, it seems like lots of folks online use task scheduler instead based on EventViewer logs. Take a look at my previous link and vbscript - WMI Event Subscription and PowerShell execution - Stack Overflow
So when I plug in USB, script will run and backup files and folders from computer to USB. I created the WMI event, there was no error. I plugged in USB, and COPY.ps1 script did not start at all.