Export windows share files

Batch file to:
extract mapped windows shares
exclude saving H:\
produce an import.bat  file to be used to remap them
only paths with spaces need to be wrapped around quotes “” manually.

 

@echo off
setlocal enabledelayedexpansion

del import_shares.bat /q

REM Run net use command and filter lines containing “\”

 

for /f “tokens=2*” %%A in (‘net use ^| find “\”‘) do (

:: remove h:\
if /i “%%A” neq “H:” (

REM Remove “Microsoft Windows Network” text
set “sharePath=%%B”
set “sharePath=!sharePath:Microsoft Windows Network=!”

REM Trim leading and trailing spaces
for /f “tokens=* delims= ” %%C in (“!sharePath!”) do set “sharePath=%%C”

REM Display the result
echo net use %%A !sharePath!
echo net use %%A !sharePath! /persistent:yes >> import_shares.bat
)

)

endlocal

TIMEOUT /T 10