특정 OU의 사용자 (User) 의 리스트를 저장하는 스크립트 입니다. DN 으로 저장됩니다.
StrOU = InputBox("Please Enter in the name of the OU that you wish to query, this needs to be in the format OU=")
Set objRootDSE = GetObject("LDAP://rootDSE")
strADsPath = "LDAP://" & strOU & "," & objRootDSE.Get("defaultNamingContext")
Set objDomain = GetObject(strADsPath)
objOutputFile = InputBox("c:\abc.txt")
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 distinguishedName FROM " + "'" + strADsPath + "'" + " WHERE objectCategory = 'CN=Person,CN=Schema,CN=Configuration,DC=xxx,DC=xxx,DC=xxx'"
-- 사용자만 추출하기 위한 부분
objCommand.Properties("searchscope") = 2
objCommand.Properties("Page Size") = 1000
Set objRecordSet = objCommand.Execute
While Not objRecordSet.EOF
objOutputFile.Write(objRecordSet.Fields("distinguishedName") & VBCRLF)
objRecordSet.MoveNext
WEnd
objOutputFile.Close
Set objFileSystem = Nothing
objConn.Close
WScript.Echo("Script Has Completed?")
이번에는 바로 소스코드에 파일 등을 박아 넣어서 돌리도록 변경하였습니다.
Set objRootDSE = GetObject("LDAP://rootDSE")
strADsPath = "LDAP://ou=개인, "& objRootDSE.Get("defaultNamingContext")
Set objDomain = GetObject(strADsPath)
Dim objConn, objRecordSet
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile("c:\userlist.txt", TRUE)
Set objCommand = CreateObject("ADODB.Command")
Set objConn = CreateObject("ADODB.Connection")
objConn.Open "Provider=ADsDSOObject;"
Set objCommand.ActiveConnection = objConn
objCommand.CommandText = "SELECT distinguishedName FROM " + "'" + strADsPath + "'" + " WHERE
objectCategory = 'CN=Person,CN=Schema,CN=Configuration,DC=xxx,DC=xxxDC=xx"
objCommand.Properties("searchscope") = 2
objCommand.Properties("Page Size") = 1000
Set objRecordSet = objCommand.Execute
While Not objRecordSet.EOF
objOutputFile.Write(objRecordSet.Fields("distinguishedName") & VBCRLF)
objRecordSet.MoveNext
WEnd
objOutputFile.Close
Set objFileSystem = Nothing
objConn.Close
WScript.Echo("Script Has Completed?")