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
697 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
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
 
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

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now