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
708 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Resolve DNS query failed errors for Exchange
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
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…
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 to another domain controller. Log onto the new domain controller with a user account t…

920 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

15 Experts available now in Live!

Get 1:1 Help Now