' Specify the last name of the user (or partial) strLastName= "horkay" ' Constants for the NameTranslate object. Const ADS_NAME_INITTYPE_GC = 3 Const ADS_NAME_TYPE_NT4 = 3 Const ADS_NAME_TYPE_1779 = 1 ' Other constants Const ADS_SCOPE_SUBTREE = 2 ' Determine DNS domain name from RootDSE object. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") 'wscript.echo strDNSDomain 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 strCommand = "SELECT distinguishedName FROM 'LDAP://" & strDNSDomain & "' WHERE objectCategory='user' " & _ "AND sn = '" & strLastName & "*'" 'wscript.Echo "strCommand = " & strCommand objCommand.CommandText = strCommand Set objRecordSet = objCommand.Execute strDisplayMessage = "(Login) - (Display Name)" intCounter = 0 Set objUser = Nothing If objRecordSet.EOF or objRecordSet.BOF Then strDisplayMessage = "No Users Found matching the last name of - " _ + strLastName + chr(10) + "In the LDAP://" & strDNSDomain Else objRecordSet.MoveFirst Do Until objRecordSet.EOF intCounter = intCounter + 1 If intCounter = 15 Then strDisplayMessage = strDisplayMessage & chr(10) & "...(" & _ objRecordSet.RecordCount & _ " users found, only display first 15, not continuing)." Exit Do End If strDN = objRecordSet.Fields("distinguishedName").Value set objUser = GetObject("LDAP://" & strDN) strDisplayMessage = strDisplayMessage + objUser.SamAccountName + " - " + objUser.FullName + chr(10) set objUser = Nothing objRecordSet.MoveNext Loop End If Wscript.Echo strDisplayMessage