wmic path win32_mappedlogicaldisk get deviceid, providername
Result:
DeviceID ProviderName
I: \\server1\Temp
J: \\server2\Corporate
Y: \\Server3\Dev_Repo
Z: \\Server3\Repository
As a batch file (src):
@if [%1]==[] goto :Usage
@setlocal enabledelayedexpansion
@set _NetworkPath=
@pushd %1
@for /f "tokens=2" %%i in ('wmic path win32_mappedlogicaldisk get deviceid^, providername ^| findstr /i "%CD:~0,2%"') do @(set _NetworkPath=%%i%CD:~2%)
@echo.%_NetworkPath%
@popd
@goto :EOF
:: ---------------------------------------------------------------------
:Usage
@echo.
@echo. Get the full UNC path for the specified mapped drive path
@echo.
@echo. %~n0 [mapped drive path]
Example:
C:\> get-unc-path.bat z:\Tools\admin
\\EnvGeoServer\Repository\Tools\admin
Batch script adapted from https://superuser.com/a/1123556/16966. Please be sure to go vote that one up too if you like this solution.
Update 2021-11-15: bug fix. Previously the batch only reported drive letter UNC root and neglected to also report the folder path.
%CD%
is set from %%i
through some kind of CMD magic.
%CD:~0,2%
and %CD:~2%
extract the drive letter and trailing path substrings respectively. e.g. :~2%
does '\Tools\admin' from 'Z:\Tools\admin'.