Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for users with more than 4 characters in username

Status
Not open for further replies.

uffolsen

IS-IT--Management
Oct 4, 2007
3
NO
Hi, I need some help from you experts to search AD for users that have a username that contains more than 4 characters and export this to excel. This is what I have now:

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "User Name"
objExcel.Cells(1, 2).Value = "Full Name"
objExcel.Cells(1, 3).Value = "Description"
strDomain = InputBox ("Enter Domain Name")
Set DomObj = GetObject("WinNT://" & strDomain )
DomObj.Filter = Array("User")
For Each objUser In DomObj
objExcel.Cells(intRow, 1).Value = objUser.Name
objExcel.Cells(intRow, 2).Value = objUser.FullName
objExcel.Cells(intRow, 3).Value = objUser.Description
intRow = intRow + 1
Next
objExcel.Range("A1:C1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
MsgBox "Done
 
username that contains more than 4 characters
Code:
...
For Each objUser In DomObj
  If Len(Trim(objUser.Name & "")) > 4 Then
    objExcel.Cells(intRow, 1).Value = objUser.Name
    objExcel.Cells(intRow, 2).Value = objUser.FullName
    objExcel.Cells(intRow, 3).Value = objUser.Description
    intRow = intRow + 1
  End If
Next
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top