none
Automatically ejecting USB hard drives RRS feed

  • General discussion

  • Hi,

    I'm setting up a basic standalone fileserver for a remote office, running Server 2016 Standard. It's just going to have one fileshare, and I have written a robocopy batch file to back this up once a week to a USB hard drive. I will schedule the script to run overnight on a Friday.

    I want to eject the USB hard drive once it's completed, and a bit of searching suggests usng devcon (which I have installed). There are several drives (they will be used in rotation, but all are the same model), and I have written a batch file with the command:

    devcon remove @swd\wpdbusenum\*

    I have four of the drives connected at the moment for testing. When I run the batch file (from an elevated command prompt) it returns:

    SWD\WPDBUSENUM\{FF6391A0-FAA5-11E7-A2C9-509A4C77EFC3}#0000000008100000: Removed
    SWD\WPDBUSENUM\{FF63901E-FAA5-11E7-A2C9-509A4C77EFC3}#0000000008100000: Removed
    SWD\WPDBUSENUM\{FF6391D6-FAA5-11E7-A2C9-509A4C77EFC3}#0000000008100000: Removed
    SWD\WPDBUSENUM\{20250FA9-FC50-11E7-A2CA-806E6F6E6963}#0000000008100000: Removed
    4 device(s) were removed.

    However, the four drives are all still visible and accessible, so it clearly hasn't actually removed them.

    I have also tried a powershell script, as follows:

    $vol = get-wmiobject -Class Win32_Volume | where{$_.Name -eq 'F:\'}  
    $vol.DriveLetter = $null  
    $vol.Put()  
    $vol.Dismount($false, $false)

    This does work, but introduces another problem in that when the drive is plugged back in, even if the server has been rebooted, it doesn't automatically assign the drive letter, and I've had to go into disk management to do that manually - so that's not a solution unless I can find a way to automate the re-allocation of the drive letter.

    I have also tried using diskpart, but that causes the same issue as above, i.e. the drive letter is not automatically re-assigned when the drive is connected again.

    So what I basically need is a script (or scripts) which:

    1) Eject the drive once the backup has completed.
    2) Automatically re-assign the letter when it's next connected.

    Any help much appreciated.

    Thanks!


    David

    • Changed type Bill_Stewart Monday, March 12, 2018 8:21 PM
    • Moved by Bill_Stewart Monday, March 12, 2018 8:21 PM This is not "scripts on demand"
    Friday, January 19, 2018 3:49 PM

All replies

  • You're presuming that what you want to do is possible from a script.

    It may be theoretically possible, but unfortunately we don't have the resources to take on this project for you for free.

    If this is critical to your business, we would recommend hiring a consultant.


    -- Bill Stewart [Bill_Stewart]


    Friday, January 19, 2018 4:37 PM
  • This used to work:

    (new-object -COM Shell.Application).NameSpace(17).ParseName('D:').InvokeVerb('Eject')


    \_(ツ)_/

    Friday, January 19, 2018 4:41 PM