Set objNetwork = CreateObject("Wscript.Network") objToFind = objNetwork.ComputerName ExecuteSearch = SearchDistinguishedName(objToFind) Public Function SearchDistinguishedName(ByVal vSAN) Const ADS_SCOPE_SUBTREE = 2 Dim oRootDSE, oConnection, oCommand, oRecordSet Set oRootDSE = GetObject("LDAP://rootDSE") Set oConnection = CreateObject("ADODB.Connection") oConnection.Open "Provider=ADsDSOObject;" Set objCommand = CreateObject("ADODB.Command") objCommand.ActiveConnection = oConnection ldstring = "'LDAP://OU=Agencies,dc=ad,dc=dot,dc=gov'" objCommand.CommandText = "Select Name, distinguishedName from "& ldstring & " where objectClass='computer'" objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 30 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF If lcase(objRecordSet.Fields("Name").Value) = lcase(vSan) Then Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value & vbCrLf _ & "Location: " & objRecordSet.Fields("distinguishedName").Value 'Wscript.Quit End If objRecordSet.MoveNext Loop End Function Set objNetwork = Nothing Set oRootDSE = Nothing Set oConnection = Nothing Set objCommand = Nothing Set objRecordSet = Nothing