Oisin (x0n) Grehan wrote a module for PowerShell 2 which uses the WMI ManagementEventWatcher and the new event-handling features of PowerShell 2.0 to automatically run scripts whenever you plug in or unplug a removable drive …. specifically, the AutoMount module runs New-PSDrive whenever you plug in a removable, and Remove-PSDrive when you unplug it.

The bottom line is it works great (at least on Vista), and I think I’ll add it to my “AutoModules” ;) ... sadly, it’s not on PoshCode yet :/ but you should go- check it out, it’s a great example of how to work with events in PowerShell, both consuming and creating them (incidentally, x0n’s PSEventing snapin would let you accomplish this in PowerShell v1). [new] x0n’s posted it on PoshCode, so you can Get-PoshCode 525 if you have the module or script installed, or download it from the embed link below: