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
718 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
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.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

832 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