Sunday, July 11, 2010

alrighty then...

well that was way more effort than it was worth. I'm sure there must be an easier way to do this (most likely using wmic), but without using external tools, this is how i did it. The following command outputs only the drive letter and share path of active network drive mappings:

FOR /F "usebackq tokens=2,3 delims= " %i in (`findstr /r ^OK nu.test`) do @echo %i %j

This is the output: (i mapped the same path to 2 diff letters)
K: \\192.168.1.202\share
Z: \\192.168.1.202\share

so to incorporate this into the script i was working on (to back up network drives to a file for later restore) this is the code:

FOR /F "usebackq tokens=2,3 delims= " %i in (`findstr /r ^OK nu.test`) do @echo %i %j >> mappings.dat

FOR /F "tokens=1,2 delims= " %i in (mappings.dat) do net use %i %j

Like i said, it may not be a thing of beauty, but it works....

****REMEMBER***
If you want to use the above code in a batch file you need to make sure the variables have double % signs, otherwise it wont work.

*EDIT*
Like I said at the beginning of the post, there must be an easier way of doing this...there is...
wmic netuse get localname,remotepath

No comments:

Post a Comment