请教如何将AD中一个组的成员定期导入SQL
在我的AD里有一个全局的安全性群组包含一些计算机
这个群组里的数据每天都会有变动,想要把这个群组里的计算机名称每天定期导入SQL里做查询
目前想到可以用VBS脚本将群组里的信息拉出来,成csv格式,但如何导入到SQL就没有办法了
各位有何高见,请指教,谢谢
这个群组里的数据每天都会有变动,想要把这个群组里的计算机名称每天定期导入SQL里做查询
目前想到可以用VBS脚本将群组里的信息拉出来,成csv格式,但如何导入到SQL就没有办法了
各位有何高见,请指教,谢谢
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT cn,name,distinguishedName FROM 'LDAP://cn=USB,ou=Wireless,ou=Clients,ou=lms,dc=lms,dc=test' WHERE objectCategory='group'"
Set objRecordSet = objCommand.Execute
"SELECT cn,name,distinguishedName FROM 'LDAP://cn=USB,ou=Wireless,ou=Clients,ou=lms,dc=lms,dc=test' WHERE objectCategory='group'"
Set objRecordSet = objCommand.Execute
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Set objWorksheet = objWorkbook.Worksheets.add()
objWorksheet.Name = objRecordSet.Fields("name").Value
dn=objRecordSet.Fields("distinguishedName").Value
Set objGroup = GetObject("LDAP://"+dn)
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
i=1
For Each strMember in arrMemberOf
set member=GetObject("LDAP://"+strMember)
member.GetInfo
objExcel.Cells(i,1).Value = member.GetEx("sAMAccountName")
objExcel.Cells(i,2).Value = member.GetEx("name")
i=i+1
Next
Do Until objRecordSet.EOF
Set objWorksheet = objWorkbook.Worksheets.add()
objWorksheet.Name = objRecordSet.Fields("name").Value
dn=objRecordSet.Fields("distinguishedName").Value
Set objGroup = GetObject("LDAP://"+dn)
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
i=1
For Each strMember in arrMemberOf
set member=GetObject("LDAP://"+strMember)
member.GetInfo
objExcel.Cells(i,1).Value = member.GetEx("sAMAccountName")
objExcel.Cells(i,2).Value = member.GetEx("name")
i=i+1
Next
objRecordSet.MoveNext
Loop
答案或建议:
找到了,在SQL里排定Job执行下面的语句即可:
SELECT name, mail
FROM OPENQUERY( ADSI,
'SELECT name, mail
FROM ''LDAP:// DC=[domain],DC=[tld]'' WHERE
memberOf=''CN=[groupname],OU=[organizationalunit],DC=[domain],DC=[tld]'' AND
objectCategory=''Person'' AND objectClass = ''USER''')
Variables are marked with brackets:
[domain] = Name of the Active Directory domain (e.g. "YourDomain")
[tld] = Name of the top level domain (e.g. "local")
[groupname] = This is the name of the security group whose members you want
to know (e.g. "Domain Admins")
[organizationalunit] = Name of the organizational unit (e.g. "Users")
文章出自:http://www.baikewenda.com/h/1102/a37177.html
本站其它内容:
→WORD 2007中竟然无法插入特殊符号
→求好用的键盘控制鼠标的软件
→安装win7-WinXP双系统后启动菜单的恢复
→UPS电源停电后可以自动关机吗?
→uvz格式的电子书如何打开?
→此iphone不能使用 因为所需的软件未安装
→此iPhone不能使用,因为Apple Mobile Device服务没有启动
→有没有清理右键新建菜单项的小工具?
→android手机怎么发彩信
→VEGAS或AE怎么做到视频只有一部分有颜色
→因iastor.sys引起的蓝屏问题
→Win7桌面上的程序快捷方式全都打不开了,怎么办?
→为什么安装ie9时老是安装失败呢?
→Windows7 中文家庭高级版为什么不能激活?
→maya里按P键和约束里的父子有什么区别啊?
→AfterEffect CS3中怎么抠动态图
→求好用的键盘控制鼠标的软件
→安装win7-WinXP双系统后启动菜单的恢复
→UPS电源停电后可以自动关机吗?
→uvz格式的电子书如何打开?
→此iphone不能使用 因为所需的软件未安装
→此iPhone不能使用,因为Apple Mobile Device服务没有启动
→有没有清理右键新建菜单项的小工具?
→android手机怎么发彩信
→VEGAS或AE怎么做到视频只有一部分有颜色
→因iastor.sys引起的蓝屏问题
→Win7桌面上的程序快捷方式全都打不开了,怎么办?
→为什么安装ie9时老是安装失败呢?
→Windows7 中文家庭高级版为什么不能激活?
→maya里按P键和约束里的父子有什么区别啊?
→AfterEffect CS3中怎么抠动态图