[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 646
  • Last Modified:

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?  :)
0
gilbar
Asked:
gilbar
  • 7
  • 4
  • 3
  • +2
1 Solution
 
Joseph O'LoughlinCommented:
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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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
 
gilbarAuthor Commented:
aha!!!  i should have of that!!! Thank you oBda!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now