Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Windows › Trying to locate windows event log for automated script w/ USB plug-in
New Posts  All Forums:Forum Nav:

Trying to locate windows event log for automated script w/ USB plug-in

post #1 of 3
Thread Starter 
Hello all,

Alright, this is an odd request but I would like to be able to run a .ps1 script execute upon an event specific to an external drive being plugged into a specific USB port.

The powershell script contains a few robocopy commands, Acronis commands and a few other disk cleanup (defrag, check disk etc) related commands and then ejects the drive, The script isn't the problem. Its having the script run at the specific event that I am trying to locate.

I know that there are programs out there that do the sync, and I can set up Acronis to back up to the drive on a schedule etc. However, the point for doing it the long/complex way is for personal gain rather than the easy way out. I like to know what I'm doing, when I'm doing it, and know that there isn't anything else that is going on during that time that is unbeknownst to me. thumb.gif

I am using this to both help me both in my workings with windows at the system level rather than point and click and playing games. As well as learning to script with PowerShell. For those of you that can respect that, I humbly request assistance in finding whatever I need to, to make this work.

At the moment, I am still running with my powershell script and working out all the bugs. In the meantime, I would like to get this running on a much smaller scale copying a few pics to a thumb drive.

Details are as follows

1. The USB port is a case 3.0 port that came with my Lian Li case.

Q1) How do I locate that USB port's specific ID to enumerate in a script or WSH command?

2. The external drive is a Western Digital SES Passport 1TB USB2.0 drive. I was using it as a media bay for my PS3 and 360 however with my additions to my software and network resources i am able to stream without issue so the drive is formatted back to NTFS and not FAT32 (Thanks, M$ for being a D about it)

Q2) I have run into problems with USB 3.0 ports and USB 2.0 drives with VMWare WS 9 not recognizing, with this in mind a question came up, would the two versions of USB buses conflict and make this not work?

3. As I said I am working in PowerShell to get accustomed to it.

Q3) Is there a better language that you would prefer for this type of task? Or rather a better daily use language?

Thanks for all the assistance.

-Pyro
The Vault v2
(21 items)
 
Asus G50Vt
(11 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i5 2500K @ 4.6GHz P8Z68-V PRO NVIDIA GeForce GTX 580 NVIDIA GeForce GTX 580 
RAMHard DriveHard DriveHard Drive
G.Skill Sniper 16GB Samsung 840 Pro 256GB 2x Seagate 1.5TB RAID1 Western Digital Raptor 450GB 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital Black 1TB WD External 1TB Passport OCZ Vertex 3 120GB Sony Optiarc Slimdrive BD 
CoolingOSMonitorKeyboard
Corsair H60  Windows 7 SP1 x64 / Slackware 14.1 PB278Q CM QuickFire Rapid 
PowerCaseMouseMouse Pad
Seasonic 1050X Gold Lian Li PC-9F Logitech GX9 Steel Series QcK Mini 
Audio
Razer Circumaural Electra Headset 
CPUMotherboardGraphicsRAM
Intel Mobile Core 2 Duo T9600 G50VT GeForce 9800M GS @ 640/1600/900 Samsung  
RAMHard DriveHard DriveOptical Drive
Samsung  Toshiba SSD HGST HDD 7.2K Optiarc BD-ROM 
CoolingOSOS
Arctic Silver MX-4 Slackware 14.1 x64 Windows 7 Home Premium x64 
  hide details  
Reply
The Vault v2
(21 items)
 
Asus G50Vt
(11 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i5 2500K @ 4.6GHz P8Z68-V PRO NVIDIA GeForce GTX 580 NVIDIA GeForce GTX 580 
RAMHard DriveHard DriveHard Drive
G.Skill Sniper 16GB Samsung 840 Pro 256GB 2x Seagate 1.5TB RAID1 Western Digital Raptor 450GB 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital Black 1TB WD External 1TB Passport OCZ Vertex 3 120GB Sony Optiarc Slimdrive BD 
CoolingOSMonitorKeyboard
Corsair H60  Windows 7 SP1 x64 / Slackware 14.1 PB278Q CM QuickFire Rapid 
PowerCaseMouseMouse Pad
Seasonic 1050X Gold Lian Li PC-9F Logitech GX9 Steel Series QcK Mini 
Audio
Razer Circumaural Electra Headset 
CPUMotherboardGraphicsRAM
Intel Mobile Core 2 Duo T9600 G50VT GeForce 9800M GS @ 640/1600/900 Samsung  
RAMHard DriveHard DriveOptical Drive
Samsung  Toshiba SSD HGST HDD 7.2K Optiarc BD-ROM 
CoolingOSOS
Arctic Silver MX-4 Slackware 14.1 x64 Windows 7 Home Premium x64 
  hide details  
Reply
post #2 of 3
You can use PowerShell to react to the WMI events that are automatically generated whenever a USB device is inserted/removed. Here are a few links to get you started:

Hey, Scripting Guy! How Can I Be Notified When a USB Drive Is Plugged into My Computer?

Responding to USB Devices in PowerShell
Kota's Rig
(8 items)
 
  
CPUMotherboardGraphicsRAM
Intel C2Q X3380 @ 4.0 GHz Foxconn BLACKOPS X48 XFX 7870 Double D Black Edition 2 GB 8 GB G.Skill RipjawsX DDR3-2133 
Hard DriveCoolingPowerCase
Samsung 840 250GB Corsair Hydro H50 Push/Pull Corsair HX620 Silver AeroCool Masstige (Modded) 
  hide details  
Reply
Kota's Rig
(8 items)
 
  
CPUMotherboardGraphicsRAM
Intel C2Q X3380 @ 4.0 GHz Foxconn BLACKOPS X48 XFX 7870 Double D Black Edition 2 GB 8 GB G.Skill RipjawsX DDR3-2133 
Hard DriveCoolingPowerCase
Samsung 840 250GB Corsair Hydro H50 Push/Pull Corsair HX620 Silver AeroCool Masstige (Modded) 
  hide details  
Reply
post #3 of 3
Thread Starter 
Awesome thanks for the links. Will post back when i have a working script.
The Vault v2
(21 items)
 
Asus G50Vt
(11 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i5 2500K @ 4.6GHz P8Z68-V PRO NVIDIA GeForce GTX 580 NVIDIA GeForce GTX 580 
RAMHard DriveHard DriveHard Drive
G.Skill Sniper 16GB Samsung 840 Pro 256GB 2x Seagate 1.5TB RAID1 Western Digital Raptor 450GB 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital Black 1TB WD External 1TB Passport OCZ Vertex 3 120GB Sony Optiarc Slimdrive BD 
CoolingOSMonitorKeyboard
Corsair H60  Windows 7 SP1 x64 / Slackware 14.1 PB278Q CM QuickFire Rapid 
PowerCaseMouseMouse Pad
Seasonic 1050X Gold Lian Li PC-9F Logitech GX9 Steel Series QcK Mini 
Audio
Razer Circumaural Electra Headset 
CPUMotherboardGraphicsRAM
Intel Mobile Core 2 Duo T9600 G50VT GeForce 9800M GS @ 640/1600/900 Samsung  
RAMHard DriveHard DriveOptical Drive
Samsung  Toshiba SSD HGST HDD 7.2K Optiarc BD-ROM 
CoolingOSOS
Arctic Silver MX-4 Slackware 14.1 x64 Windows 7 Home Premium x64 
  hide details  
Reply
The Vault v2
(21 items)
 
Asus G50Vt
(11 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i5 2500K @ 4.6GHz P8Z68-V PRO NVIDIA GeForce GTX 580 NVIDIA GeForce GTX 580 
RAMHard DriveHard DriveHard Drive
G.Skill Sniper 16GB Samsung 840 Pro 256GB 2x Seagate 1.5TB RAID1 Western Digital Raptor 450GB 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital Black 1TB WD External 1TB Passport OCZ Vertex 3 120GB Sony Optiarc Slimdrive BD 
CoolingOSMonitorKeyboard
Corsair H60  Windows 7 SP1 x64 / Slackware 14.1 PB278Q CM QuickFire Rapid 
PowerCaseMouseMouse Pad
Seasonic 1050X Gold Lian Li PC-9F Logitech GX9 Steel Series QcK Mini 
Audio
Razer Circumaural Electra Headset 
CPUMotherboardGraphicsRAM
Intel Mobile Core 2 Duo T9600 G50VT GeForce 9800M GS @ 640/1600/900 Samsung  
RAMHard DriveHard DriveOptical Drive
Samsung  Toshiba SSD HGST HDD 7.2K Optiarc BD-ROM 
CoolingOSOS
Arctic Silver MX-4 Slackware 14.1 x64 Windows 7 Home Premium x64 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Windows
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Windows › Trying to locate windows event log for automated script w/ USB plug-in