Maystyle :
Admin : New post
Guestbook
Local
media
Catergories
Recent Articles
Recent Comments
Recent Trackbacks
Calendar
Tag
Archive
Link
Search
 
  특정 OU의 사용자 리스트를 파일로 추출하는 스크립트 
작성일시 : 2008. 2. 21. 16:55 | 분류 : Windows Server/Active Directory | 태그 : , , ,

특정 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?")

Name   Password   Home   Secret   Submit
 Prev   1   ···   282   283   284   285   286   287   288   289   290   ···   517   Next