Powershell Eject of USB Works how could I remount it without reconnecting the device
-
So this is what I have currently
$driveEject = New-Object -comObject Shell.Application $driveEject.Namespace(17).ParseName("E:").InvokeVerb("Eject")
This works to eject a USB drive mapped to E:
Now what would I have to do to remount the drive after 5 minutes (for example).
Yes, I'm fixing a personnel issue with technology, and no I don't care to hear about fixing the personnel issues - because I'm not in a position to fix them.
This is a means to fix those issues and save me and my team effort by conforming to stupid requests.
-
rescan from disk manager or disable and enable in disk manager work
I would assume there are command line equivalents for that.
-
@jaredbusch yeah that is what I was just thinking about, just trying to figure out what the comparable is.
-
The issue is that as soon as the USB drive is removed, I'll have to rescan for all drives, select the correct one, by parsing through diskpart line by line like
"list disk" | dispart
hopefully find the correct one by randomly selecting it (disk 4, 5 6 etc) and then I could possibly remount it.... -
@dustinb3403 said in Powershell Eject of USB Works how could I remount it without reconnecting the device:
The issue is that as soon as the USB drive is removed, I'll have to rescan for all drives, select the correct one, by parsing through diskpart line by line like
"list disk" | dispart
hopefully find the correct one by randomly selecting it (disk 4, 5 6 etc) and then I could possibly remount it....If it should always be the same USB disk, can you get the disk label?
So that before you eject the disk, get the label of the disk. Eject the disk, and then in 5 minutes do the rescan, and find which disk has that label?
-
@dafyre no, the label changes, week 1, week 2 etc.
The reason for wanting for check in some duration (5m) is because apparently these people can't be bothered to actually swap the drive every week.
So, eject the drive, and check in 5 if the disk uid is still around and reconnect
-
@dustinb3403 said in Powershell Eject of USB Works how could I remount it without reconnecting the device:
@dafyre no, the label changes, week 1, week 2 etc.
The reason for wanting for check in some duration (5m) is because apparently these people can't be bothered to actually swap the drive every week.
So, eject the drive, and check in 5 if the disk uid is still around and reconnect
Every time, yep.
-
@dustinb3403 said in Powershell Eject of USB Works how could I remount it without reconnecting the device:
@dafyre no, the label changes, week 1, week 2 etc.
The reason for wanting for check in some duration (5m) is because apparently these people can't be bothered to actually swap the drive every week.
So, eject the drive, and check in 5 if the disk uid is still around and reconnect
Perhaps use an usb hub and have more drives, say 5 or something. so you can swap more seldom.
Also have the machine beep and send emails / text reminder every hour until the drive has been swapped.
But if it's some kind of backup, why use usb drives at all?
-
@pete-s said in Powershell Eject of USB Works how could I remount it without reconnecting the device:
But if it's some kind of backup, why use usb drives at all?
Because that is what this customer wants for these systems. I don't get it either
-
@dustinb3403 said in Powershell Eject of USB Works how could I remount it without reconnecting the device:
@pete-s said in Powershell Eject of USB Works how could I remount it without reconnecting the device:
But if it's some kind of backup, why use usb drives at all?
Because that is what this customer wants for these systems. I don't get it either
OK, well I'd go for checking the disk label and send reminders until the correct drive is mounted. With some kind of escalation to their boss after X hours.
-
@pete-s said in Powershell Eject of USB Works how could I remount it without reconnecting the device:
@dustinb3403 said in Powershell Eject of USB Works how could I remount it without reconnecting the device:
@pete-s said in Powershell Eject of USB Works how could I remount it without reconnecting the device:
But if it's some kind of backup, why use usb drives at all?
Because that is what this customer wants for these systems. I don't get it either
OK, well I'd go for checking the disk label and send reminders until the correct drive is mounted. With some kind of escalation to their boss after X hours.
I'd be okay with this, although the End User may actually be annoyed at getting the "Change The Backup Drive, you Moron" emails and actually do it, lol.
-
Okay so I've ended up going a different way with this, but I believe the results are the same.
This will disable the PNP device, based on the InstanceID
Disable-PnpDevice -InstanceID 'USB\VID_1B1C&PID_1A06\AA1TD4DI0B5WBKJG' -A
and this will enable the PNP Device
Enable-PnpDevice -InstanceID 'USB\VID_1B1C&PID_1A06\AA1TD4DI0B5WBKJG' -A
Also based on the InstanceID
While this isn't perfect (I need to know the instance ID of each USB device) it does make it simple to pull this detail from each device and build 1 or 2 scripts to do everything.
-
Things to consider if you do this yourself, once you disable a device if you don't enable it again, it will remain disabled in device manager between subsequent removal/installation.
So it's critical to enable any disabled devices after the fact, or you'll have to manually enable the device through device manager.