Solved

Search for Active Direcotry fields longer than a certain length

Posted on 2009-07-06
4
642 Views
Last Modified: 2013-12-24
I have a situation that came up that requires me to find all of the users in our AD environment whos title field is longer than 40 characters. I am pretty familiar with the DS fmaily of commands but I do not think this can be done using those. I have taken a look at some other tools but nothing really jumps out to me. I am hoping someone else out there might have some insight or other tools to try in order to search for and return users whos title field is longer than X characters.

0
Comment
Question by:Joseph Daly
4 Comments
 
LVL 14

Expert Comment

by:Wonko_the_Sane
ID: 24785236
One pretty simple way should be to use VBScript.
I won't give the details, if you are familiar with most commands it should be fairly, plus there will be a ton of examples on the Internet.

Basically you will you ADSI in VBS to loop through all your users. Read the title field, use the "LEN" command to determine the length of the string, and output the User DN or something if > 40.

Or use dsquery user to get all users, pipe it to "dsget user -dn -title", direct the output to a file, and use Excel to determine the fields longer than 40 characters. Probably a little easier, but more manual effort.

dsquery user -name * -limit ???? | dsget user -dn -title > list.txt
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 24785509

Hey xxdcmast :)

You can do far worse than PowerShell for these odd little jobs.

Grab this:

http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx

Then this:

http://www.quest.com/activeroles-server/arms.aspx

Then you can run this tiny command to find them:

Get-QADUser | ?{ $_.Title.Length -gt 40 }

It'll let you export that to a CSV file easily enough with:

Get-QADUser | ?{ $_.Title.Length -gt 40 } | Export-CSV "SomeFile.csv"

Or you can do other stuff with it depending on your needs.

Chris
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24785526
Paste the script below into a text file with a .vbs extension.  Customize the value of the strContainer variable on line 3 with the distinguished name of the domain or OU to search under.

Running the script will search for users whose Title attribute is over 40 characters long and write their distinguished names, titles, and title lengths to a comma-delimited text file.


Const ADS_SCOPE_SUBTREE = 2
 

strContainer = "dc=yourdomain,dc=local"

strField = "Title"

intLength = 40

strReport = "report.csv"
 

On Error Resume Next
 

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objReport = objFSO.CreateTextFile(strReport, True)
 

objReport.WriteLine "User,Field Value,Field Length"
 

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

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 

objCommand.CommandText = "SELECT ADSPath," & strField & _

    " FROM 'LDAP://" & strContainer & "' " & "WHERE objectCategory='user'"  

Set objRecordSet = objCommand.Execute
 

objRecordSet.MoveFirst
 

Do Until objRecordSet.EOF

    Set objUser = GetObject(objRecordSet.Fields("ADSPath").Value)

    strValue = objRecordSet.Fields(strField).Value

    

    If Len(strValue) > intLength Then

        objReport.WriteLine Chr(34) & objUser.distinguishedName & _

            Chr(34) & "," & strValue & "," & Len(strValue)

    End If

    

    objRecordSet.MoveNext

Loop
 

objReport.Close

Open in new window

0
 
LVL 35

Author Closing Comment

by:Joseph Daly
ID: 31600167
These tools are pretty awesome.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

929 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

9 Experts available now in Live!

Get 1:1 Help Now