Solved

Search for Active Direcotry fields longer than a certain length

Posted on 2009-07-06
4
641 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
These tools are pretty awesome.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Resolve DNS query failed errors for Exchange
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

744 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

8 Experts available now in Live!

Get 1:1 Help Now