vbscript 导出OU计算机

Posted

tags:

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

Const ADS_SCOPE_SUBTREE = 200

strExportFile = "AD_OU_Export_Computers.csv"
strSelectAttr = "cn, operatingSystem, operatingSystemServicePack"

' Get OU
strOU = "OU=Laptops W7,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
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

' Execute command to get all users in OU
objCommand.CommandText = _
    "Select " & strSelectAttr & " from 'LDAP://" & strOU & "' " _
        & "Where objectClass='computer'"  
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 & strExportFile

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

ExportFile.WriteLine("CN;operatingSystem;operatingSystemServicePack")

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

	' Export required info for a computer
	ExportFile.WriteLine(objRecordSet.Fields("cn").Value & ";" & _
		objRecordSet.Fields("operatingSystem").Value & ";" & _
		objRecordSet.Fields("operatingSystemServicePack").Value)

	' 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计算机的主要内容,如果未能解决你的问题,请参考以下文章

导出OU下的计算机,最后一次登录

的前面 先导出OU 先导入OU

导出指定OU中的用户

按照OU批量导出用户邮件为PST格式 并导入

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

AD导出域账户