[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
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
Medium Priority
?
750 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 1000 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 1000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Suggested Courses

872 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