Skip to content

Instantly share code, notes, and snippets.

@Techlogist
Last active October 3, 2021 12:34
Show Gist options
  • Save Techlogist/9374e6b15a4825c8043852b398b4d000 to your computer and use it in GitHub Desktop.
Save Techlogist/9374e6b15a4825c8043852b398b4d000 to your computer and use it in GitHub Desktop.
Copy all currently mapped drives
REM License: GNU General Public License v2.0
REM Author: Miguel
REM Website: www.techlogist.net
REM Post: https://techlogist.net/batch/copy-all-currently-mapped-drives
REM Description: This script helps users to migrate mapped drives between Windows 10 computers. The batch will setup assuming that it will be used inside the same domain and network and that the first user will grant accessck
REM OS/Language/Region: Windows/EN-US
@echo off
title Copy all user mapped drives
color f0
mode con:cols=70 lines=10
goto start
:start
REM Set the name of the outputfile
set _file_name=Drives-Of-%username%.txt
set _file_folder=C:\users\%username%\downloads\Drives-Of-%username%
set _launch_bat=%_file_folder%\%_file_name%
REM Create a folder
del %_file_folder% /Q
rmdir %_file_folder% /S /Q
mkdir %_file_folder%
REM Create the mapping batch
cls
echo.
echo Setting the file in the download folder
echo.
echo @echo off>%_launch_bat%
echo Title Map Drives from %username%>>%_launch_bat%
echo set _domain=%userdomain%>>%_launch_bat%
echo set _username=%username%>>%_launch_bat%
echo echo.>>%_launch_bat%
echo set /p _password=Type in password from %username%:>>%_launch_bat%
echo cls>>%_launch_bat%
REM Get the currently mapped drives in OK status and create map command
for /f "tokens=1,2,3" %%g in ('net use^|find /i ":"') do if "%%g" EQU "OK" echo net use * %%i /persistent:yes>>%_launch_bat%
for /f "tokens=1,2,3" %%g in ('net use^|find /i ":"') do if "%%g" NEQ "OK" echo net use * %%h /persistent:yes>>%_launch_bat%
echo exit>>%_launch_bat%
start explorer.exe %_file_folder%
goto _change
:_change
REM Change the file from TXT to BAT
cd %_file_folder%
rename *.txt *.bat
goto exit
:exit
cls
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment