vbscript 导出OU成员

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 导出OU成员相关的知识,希望对你有一定的参考价值。

Const ADS_UF_ACCOUNTDISABLE = 2

' Get OU
strOU = "OU=Users,OU=Organisatie,DC=VERZ,DC=LOCAL"

' Create connection to AD
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

' Create command
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000

' Execute command to get all users in OU
objCommand.CommandText = _
  "<LDAP://" & strOU & ">;" & _
  "(&(objectclass=user)(objectcategory=person));" & _
  "adspath,distinguishedname,sAMAccountName,displayName,userAccountControl;subtree"
Set objRecordSet = objCommand.Execute

' Create the Export File
Set objFSO = CreateObject("Scripting.FileSystemObject")
strScriptDir = Left(WScript.ScriptFullName, (Len(WScript.ScriptFullName))-(Len(WScript.ScriptName)))
strExportFileName = strScriptDir & "AD_OU_Export.csv"

Set ExportFile = objFSO.OpenTextFile(strExportFileName, 2, True)



' Show info for each user in OU
Do Until objRecordSet.EOF

    intUAC = objRecordset.Fields("userAccountControl")
    If intUAC AND ADS_UF_ACCOUNTDISABLE Then
		' User is disabled
	Else
		' Export required info for a user
		ExportFile.WriteLine(objRecordSet.Fields("sAMAccountName").Value & ";" & objRecordSet.Fields("displayName").Value & ";" & objRecordSet.Fields("distinguishedname").Value) 
	End If

	' Move to the next user
	objRecordSet.MoveNext

Loop

' Close the Export File
ExportFile.Close

' Clean up
objRecordSet.Close
Set objRecordSet = Nothing
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing

MsgBox "Klaar"

以上是关于vbscript 导出OU成员的主要内容,如果未能解决你的问题,请参考以下文章

CSVDE导出AD域下指定子OU的Group中所有成员的信息

导出一个OU的所有的组和组成员-PS

vbscript 导出AD组成员

如何导出域控的用户组内成员清单?

的前面 先导出OU 先导入OU

导出指定OU中的用户