Solved

VB Script to query Active Directory to get the UserName, OU user is in, and what their Home folder is set to under the Profile Tab.

Posted on 2011-02-22
6
730 Views
Last Modified: 2012-05-11
Hello,

I have searched through about 10 pages, but have yet to find the information. I have found some similar queries, but nothing I can use. I need a VB script that will give me the UserNames, the OU the users are in, and what their Home folder is set to under the Profile Tab in Active Directory.

Thank you!
0
Comment
Question by:metroacct
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:Emma567
ID: 34952651
Does it have to be a VB script?  This would be really easy to do with powershell and a free download of quest ad cmdlets using get-qaduser
0
 

Author Comment

by:metroacct
ID: 34952866
I was asked for a VB script and still need a VB script; however, I'd be willing to look into your solution.
0
 
LVL 3

Accepted Solution

by:
sam0x01 earned 250 total points
ID: 34953116
Hi,

I am at home and cant test this on a domain.

homeDirectory should work

think adsPath contains the OU but is not only the OU. will probably need extracting/trimming
On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")

strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)

Wscript.Echo objUser.AdsPath
homeDirectory=objSysInfo.Get("homeDirectory")
WScript.Echo homeDirectory

Open in new window

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 250 total points
ID: 34957850
Hi, try this script.  It will list the homeDirectory value for all of your AD users into a CSV file.

Regards,

Rob.
strResults = "UserHomeFolders.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objResults = objFSO.CreateTextFile(strResults, True)
objResults.WriteLine """Username"",""OU"",""HomeFolder"""

Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("defaultNamingContext")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
strCommandText = "<LDAP://" & strDomain & ">;(&(objectCategory=person)(objectClass=user));adsPath,samAccountName,homeDirectory;Subtree"  
objCommand.CommandText = strCommandText
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
	strSamAccountName = objRecordSet.Fields("samAccountName").Value
	strOU = Mid(objRecordSet.Fields("adsPath").Value, InStr(objRecordSet.Fields("adsPath").Value, ",") + 1)
	strHomeFolder = objRecordSet.Fields("homeDirectory").Value
	objResults.WriteLine """" & strSamAccountName & """,""" & strOU & """,""" & strHomeFolder & """"
    objRecordSet.MoveNext
Loop
objResults.Close

MsgBox "Finished. Please see " & strResults

Open in new window

0
 

Author Comment

by:metroacct
ID: 35198093
I'll have to test these out and see if they give me the result I'm looking for, but they both look like wins to me.
0
 

Author Closing Comment

by:metroacct
ID: 35198630
Decided to move on with this project.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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