Identify USB Flash drive by volume ID

Feed: Scriptorlog
Posted on: Thursday, November 25, 2010 12:00 PM
Author: iRobx
Subject: Identify USB Flash drive by volume ID

I backup my data folder to a flash drive. The problem is that the flash drive may have an arbitrary drive letter depending on when it was inserted. As I use many different flash drives and external USB hard drives, not to mention network drives, this makes creating a backup script a bit problematic. This script finds the volume ID on all local drives and selects the one for my backup flash drive to do my robocopy backup with. I use the wmic command to show volume ID’s. This is the command: wmic volume get deviceid,caption. Please note I use the /mir switch with robocopy which can delete data on your destination.


@echo off
wmic volume get deviceid,caption | findstr 00000000-abab-abab-abab-000000000000>nul
if errorlevel 1 echo Please Insert backup flash drive with Volume ID 52363c07-abab-abab-abab-001a4d53dbab && goto :EOF

for /f %%i in (' "wmic volume get deviceid,caption" ^| findstr 00000000-abab-abab-abab-000000000000') do set backupflashdrive=%%i

set backupflashdrive=%backupflashdrive: =%
echo Backup Flash drive found on {%backupflashdrive%}

if exist %backupflashdrive%data robocopy \\goliath\c$\data %backupflashdrive%data /r:0 /w:0 /mir
This entry was posted in NT Shell Scripts. Bookmark the permalink.

5 Responses to Identify USB Flash drive by volume ID

  1. Jon says:

    This is exactly what I was looking for! I’m tweaking the robocopy a bit, but I needed a shell script to find the drive letter of a disk with a known volume ID, and then execute robocopy to that drive letter. Thanks for posting this!

  2. Merle says:

    Heya i am for the first time here. I came across this board and I to find
    It truly helpful & it helped me out a lot. I’m hoping to offer one thing back and aid others like you aided me.

  3. core says:

    Why not just use \\?\{00000000-abab-abab-abab-000000000000}\data as your robocopy destination instead of trying to find the drive letter for it?

  4. core says:

    Whoops I left out the Volume{} part but you get the idea. Seems like this would be way simpler. I just stumbled across this page trying to find out if there are any drawbacks.

  5. irobx says:

    That would be a neat trick, but it does not seem to work for me.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s