Link to home
Start Free TrialLog in
Avatar of gilbar
gilbar

asked on

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?  :)
Avatar of Joseph O'Loughlin
Joseph O'Loughlin
Flag of Ireland image

Hi gilbar,

echo %homedrive%
echo %homepath%

usual disclaimers apply

---------------------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

Not sure how you'd find out from a remote machine... (assuming that's your goal)
Avatar of gilbar
gilbar

ASKER

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?
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]

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
Avatar of gilbar

ASKER

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
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]
Avatar of gilbar

ASKER

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
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]
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]
Unless, of course, someone can locate a value in the HKLM\HKU roots, storing the HOMEDRIVE...?

[r.D]
(Note: for the above code, you must add speech marks ("") round the %%W variable, when being passed to ':PROCESS')
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]
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gilbar

ASKER

aha!!!  i should have of that!!! Thank you oBda!!