need a batch command to list a user's Home directory drive letter from active directory

Hi experts;
I need to find out what drive letter each of our users has their Home directory mapped to. I can manually find this out by going onto Active Directory and pulling up a user's profile and checking Home Folder->Connect to find out that they're mapping (say) drive U: to (say) \\serv1\UserHomes\SomeUserName  but i want to be able to do this in a batch.  I can use:
   net user SomeUserName /domain
to find out what user SomeUserName's home directory is when it gives me this line:
   Home directory               \\serv1\UserHomes\SomeUserName  
but i also want to be able to find out what drive letter is being mapped to that path.  Anyone have any ideas?  Anyone understand what i'm talking about? Anyone wondering what i think this has to do with MS-DOS?  :)
LVL 9
gilbarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joseph OLoughlinIT Support SpecialistCommented:
Hi gilbar,

echo %homedrive%
echo %homepath%

usual disclaimers apply
0
brianadkinsCommented:

---------------------8<---------------------
@echo off
for /f "tokens=3" %%a in ('net user tc00680 /domain ^|findstr "home directory"') do (
call :PROCESS %%a
)

goto :END
:PROCESS
set HOMEUNC=%1
for /f "tokens=2" %%k in ('net use ^|findstr "%HOMEUNC%"') do (
echo %%k
)

:END
---------------------8<---------------------


but I guess this only works on that users computer while he/she is logged in....

-Brian
0
brianadkinsCommented:

Not sure how you'd find out from a remote machine... (assuming that's your goal)
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

gilbarAuthor Commented:
wow that was fast!  the problem is, i won't be sign'd onto the user's computer; i'll have to be getting this from the domain, any ideas?
0
DrWarezzCommented:
Oh, for a remote search, I believe that you'll either need to use an external utility, or create something that runs on ALL of the computers that you want to check.  :-\

[r.D]
0
brianadkinsCommented:

You could have eneryone's login script enter their data into a master list somewhere that you could then check with a separate script....  It won't work today... but tomorrow, you should have some good data.

--------------8<----------------------
for /F "tokens=2-4 delims=/ " %%f in ('date /t') do (
set YYYYMMDD=%%h%%f%%g
)
echo %USERNAME%,%COMPUTERNAME%,%HOMEDRIVE%,%HOMEPATH%,%YYYYMMDD% >> \\servername\userlist.csv
--------------8<----------------------

-Brian
0
gilbarAuthor Commented:
brianadkins; that's a good idea, but there's no way that my team leader would go for that.  It's looking like the answer is to tell her:can't be done.'  Which is kinda wierd since AD knows.  But thanx all.  I'm going to leave this open for a while just in case some one comes up with something
0
DrWarezzCommented:
Incase no-one else appears with some great idea as to how to do this; could you tell us what you're trying to achieve her? ie; WHY to you need the HOMEDRIVES of all the machines? I'm asking, because we may be able to figure an alternative method to your initial problem...? :-)

[r.D]
0
gilbarAuthor Commented:
oh, that's an easy one: because my team leader wants it :)  seriously, we're making some network moves and we're sending out a email warning people to let us know if they experience problems with their 'U:\' drives and leader wanted to make sure that was where the userhomes were pointing to.  I've since gone through AD manually and checked each user (only about 800 people on this move), which was not fun; but is Done.  Since AD knows where the homedrives are, it seems sensatable that it'd be willing to let us know, but apparently not.  Could still use an answer, 'cause will be doing this again i'm sure
0
DrWarezzCommented:
Hmm.. I have an idea, it should work, assuming you can access all other machines registry via your own machine. Try this:

:---------8<-------------------------------------- FileName.bat ----------------------------------------------------------:
@ECHO OFF

set machine=locahost

for /f "tokens=* skip=4 delims=" %%W in ('REG QUERY "\\%machine%\HKCU\Volatile Environment" /v HOMEDRIVE') do call :PROCESS %%W

echo.
echo [press any key to exit]
pause >>NUL
exit

:PROCESS
set line=%~1
set line=%line: =%
set drive=%line:~-2%

ECHO.
ECHO Machine: %machine%
ECHO HomeDrive: %drive%
EXIT /B
:---------8<-------------------------------------- FileName.bat ----------------------------------------------------------:

Give that a go :-)
[r.D]
0
DrWarezzCommented:
Oh, actually.. I tested it, and found out that you can't access the HKCU root of a remote machine.. :-(  So, scrap that idea

[r.D]
0
DrWarezzCommented:
Unless, of course, someone can locate a value in the HKLM\HKU roots, storing the HOMEDRIVE...?

[r.D]
0
DrWarezzCommented:
(Note: for the above code, you must add speech marks ("") round the %%W variable, when being passed to ':PROCESS')
0
DrWarezzCommented:
Ah, I located it in the HKU root. So, if you can access registy remotely, then this should do the job:


@ECHO OFF

set machine=\\remoteMachine

for /f "tokens=* skip=4 delims=" %%W in ('REG QUERY "%machine%\HKU\S-1-5-21-645757453-2505351160-3990708003-1005\Volatile Environment" /v HOMEDRIVE') do call :PROCESS "%%W"

echo.
echo [press any key to exit]
pause >>NUL
exit

:PROCESS
ECHO.
set line=%~1
set line=%line: =%
set drive=%line:~-2%

ECHO.
ECHO Machine: %machine%
ECHO HomeDrive: %drive%
EXIT /B



gL,
[r.D]
0
oBdACommented:
If you're using a Server 2003 AD (or Windows 2000 SP3 as AD, and XP for administrative Tasks, plus a W2k3 Server to get the tools), you can easily do it with dsquery and dsget:

@echo off
dsquery user -limit 0 | dsget user -samid -hmdrv

The new command-line tools for Active Directory in Windows Server 2003
http://support.microsoft.com/?kbid=298882
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gilbarAuthor Commented:
aha!!!  i should have of that!!! Thank you oBda!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.