We help IT Professionals succeed at work.

Query Active directory for user's profile path

Medium Priority
Last Modified: 2012-05-06
I need to figure out a way to query active directory for a users profile path.  I need to be able to script this with command line input and output.  I want to be able to feed a script a username and the only thing it would output is that user's profile path (or ultimately just the profile server)I also do not want to have to enter the LDAP information.  

What I was trying to use was ADFind: adfind.exe -f "sAMAccountName=administrator"  
Which gives me a lot of information, but no Profile path.  

If anyone has something along those lines that will give me the profile information, I am all ears.  Thank you !
Watch Question

DrDave242Principal Support Engineer

The "dsget user" command used with the "-profile" switch will return a user's profile path.  It requires a user's distinguished name as input, but you can use the "dsquery user" command to get that DN, then pipe dsquery's output directly to dsget.  Here's more info on it, including a couple of examples:


Have a look at "dsquery user" as well:

Top Expert 2013

for adfind you can run
adfind -b dc=yourdomain,dc=com (or whateveryour suffix is)  -f "samaccountname=username" homedirectory
That can be expanded to search for all users
What do you mean you do not want to have to enter the LDAP information?  You'll need to enter -some- qualifying information, such as the username, or any query tool isn't going to be very useful for you.

To restrict your query to only the Home Directory path, query against the 'homeDirectory' attribute - if nothing is returned for a particular user, it means that the attribute isn't populated.

To use adfind as in your example:

adfind -default -f "sAMAccountName=administrator" homeDirectory

PowerShell Developer
Top Expert 2010

ADFind does return the profile path (profilePath) attribute. You're referring to the "Profile Path" field as seen in AD Users and Computers?


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Most Valuable Expert 2019
Most Valuable Expert 2018

Save this as "ProfileQuery.cmd" or whatever.cmd; it expects the user's samid as argument and will only echo the profile path (if specified in the user's properties). It will leave with error level 1 if the profile path is empty.

@echo off
set Profile=
for /f "tokens=1*" %%a in ('dsquery user -samid "%~1" ^| dsget user -profile -l ^| find /i "profile:"') do set Profile=%%b
if "%Profile%"=="" (
  echo Error: couldn't find user account, or no profile specified
  exit /b 1
) else (
  echo %Profile%

Open in new window


profilePath was actually what I was looking for.  If I use that with ADFind it gets me exactly what I need ! ( I wasn't able to see the profilepath from the information I had because sadly I had no profile set for the administrator account)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.