[Last Call] Learn how to a build a cloud-first strategyRegister Now


Query Active directory for user's profile path

Posted on 2009-02-10
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 !
Question by:heliontech
LVL 27

Expert Comment

ID: 23604560
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:

LVL 57

Expert Comment

by:Mike Kline
ID: 23604569
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
LVL 30

Expert Comment

ID: 23604572
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 71

Accepted Solution

Chris Dent earned 2000 total points
ID: 23604603

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

LVL 85

Expert Comment

ID: 23604651
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


Author Closing Comment

ID: 31545230
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)

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A hard and fast method for reducing Active Directory Administrators members.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question