Dim objFileSystem, objOutputFile, StrDomain, StrOu Sub No_Bind MsgBox("Could not bind to Ad, please check your OU paths" & err.description) Wscript.Quit End Sub ' Get Domain Information: On Error Resume Next StrOU = InputBox("Please Enter in the name of the OU that you wish to query, this needs to be in the format OU=,OU=") Set objRootDSE = GetObject("LDAP://rootDSE") strADsPath = "LDAP://" & strOU & "," & objRootDSE.Get("defaultNamingContext") Set objDomain = GetObject(strADsPath) If Err <> 0 Then Call No_Bind objOutputFile = InputBox("Please Enter in a Destination for the DN Input File") Dim objConn, objRecordSet Set objFileSystem = CreateObject("Scripting.fileSystemObject") Set objOutputFile = objFileSystem.CreateTextFile(objOutputFile, TRUE) Set objCommand = CreateObject("ADODB.Command") Set objConn = CreateObject("ADODB.Connection") objConn.Open "Provider=ADsDSOObject;" Set objCommand.ActiveConnection = objConn objCommand.CommandText = "SELECT legacyExchangeDN FROM "+"'"+strADsPath+"'"+" WHERE objectClass = 'user'" objCommand.Properties("searchscope") = 2 objCommand.Properties("Page Size") = 1000 Set objRecordSet = objCommand.Execute While Not objRecordSet.EOF objOutputFile.Write(objRecordSet.Fields("legacyExchangeDN") & vbCrLf) objRecordSet.MoveNext Wend objOutputFile.Close Set objFileSystem = Nothing objConn.Close WScript.Echo("Script Has Completed....")