I have a Node JS NW.js/Angular app that continuously runs a PowerShell script every 5 seconds to get the currently connected removable storage devices (USB thumb drives, SD cards) that I then show to the user in the UI. My question is: Is there anything I can do on the PowerShell script itself to notify me of changes rather then running it in a continuous loop? It seems fine now and working smoothly, just wondering if there's a "better" way. I'm using the node-powershell library from NPM to call the command from a simple JavaScript setInterval() method.
ConvertTo-Json @(Get-WmiObject Win32_Volume -Filter ("DriveType=2 AND FileSystem IS NOT NULL"))
Register-WmiEvent
andRegister-CimIndicationEvent
both seem to be able to do what your code is doing. i do not know if you need to leave a powershell session running for it to work, tho. [blush] i've only read about the two cmdlets.