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

x
?
Solved

Query Active directory for user's profile path

Posted on 2009-02-10
6
Medium Priority
?
5,292 Views
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 !
0
Comment
Question by:heliontech
6 Comments
 
LVL 27

Expert Comment

by:DrDave242
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:

http://technet.microsoft.com/en-us/library/cc732535.aspx

Have a look at "dsquery user" as well:

http://technet.microsoft.com/en-us/library/cc725702.aspx
0
 
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
 
Thanks
Mike
0
 
LVL 30

Expert Comment

by:LauraEHunterMVP
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

0
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

by:
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?

Chris
0
 
LVL 85

Expert Comment

by:oBdA
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
setlocal
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

0
 

Author Closing Comment

by:heliontech
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)
0

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