Shared resources are common in big organizations, and being able to map them without assistance can be useful.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Note: It will duplicate the mappings everytime you run the mapping script.