• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5439
  • Last Modified:

Query Active directory for user's profile path

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
heliontech
Asked:
heliontech
1 Solution
 
DrDave242Commented:
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
 
Mike KlineCommented:
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
 
LauraEHunterMVPCommented:
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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
Chris DentPowerShell DeveloperCommented:

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
 
oBdACommented:
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
 
heliontechAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now