4

I want to backup the state of my mapped drives in Windows 7 Ent. I'm not trying to backup the contents of the drives, only the paths and assigned letters.

Say I had to perform a reinstall of Windows, I want to be able to restore all my mapped drives to the same drive letters, so //network-path/foldername/ will still be assigned to F:\ when restored.

Jonny Wright
  • 991
  • 5
  • 16
  • 36

1 Answers1

7

You have a couple/few options. Here's two:

If these are persistent drives you've mapped yourself, then entries for them should be stored in the registry under HKEY_CURRENT_USER\Network.

You could use Reg Export HKEY_CURRENT_USER\Network c:\temp\drives.reg from a command-line to export the key to a file, and then use reg import to import it again in the future.

For more info on that, check out this existing SU question:

Where does windows store network drive mappings?

If the drives are not persistent, you could use a script to output the list to a file, and use another script to import that file and create drives from it later.

Using PowerShell to do this isn't too hard; you could use something like the following...

Exporting:

# Define array to hold identified mapped drives.
$mappedDrives = @()

# Get a list of the drives on the system, including only FileSystem type drives.
$drives = Get-PSDrive -PSProvider FileSystem

# Iterate the drive list
foreach ($drive in $drives) {
    # If the current drive has a DisplayRoot property, then it's a mapped drive.
    if ($drive.DisplayRoot) {
        # Exctract the drive's Name (the letter) and its DisplayRoot (the UNC path), and add then to the array.
        $mappedDrives += Select-Object Name,DisplayRoot -InputObject $drive
    }
}

# Take array of mapped drives and export it to a CSV file.
$mappedDrives | Export-Csv mappedDrives.csv

Importing:

# Import drive list.
$mappedDrives = Import-Csv mappedDrives.csv

# Iterate over the drives in the list.
foreach ($drive in $mappedDrives) {
    # Create a new mapped drive for this entry.
    New-PSDrive -Name $drive.Name -PSProvider "FileSystem" -Root $drive.DisplayRoot -Persist -ErrorAction Continue 
}