Search code examples
windowspowershellbackupdrivedisk-partitioning

External Drive Letter - Backup


I am writing a PowerShell script that will back up several folders from my Vista drive to an external USB drive, using robocopy.
Windows does not guarantee that it will always assign the same drive letter to the external drive.
What is the best way to get around this problem?
How do I code the destination paths?

Thanks.


Solution

  • Windows could change that drive letter assigned to your USB drive.
    The correct way to do this backup is mounting the USB drive in an empty directory. Not only does it add some consistency to swapped storage, it also allows for a persistent shortcut on a Windows desktop.

    That's how to:

    1. Run "diskmgmt.msc" from Windows' Run/Start Search box,
    2. Right-click on your plugged-in drive and choose "Change Drive Letter and Paths."
    3. Remove the current drive letter assigned to your drive.
    4. Click on the Add button
    5. Select Mount into the following empty NTFS folder and click on browse.
    6. Now navigate to the subfolder that you want to assign the USB drive to and confirm the assignment.

    The USB drive will from now on be accessible from that folder (if it is connected to the computer of course).
    Now you can change your script to select, as destination folder, the folder with the mounted drive and forget the drive letter persistence.