今天是:
设百科问答网为首页|收藏百科问答网|网站地图
百科问答网 - 帮您解决问题,分享成功经验
首页(百科问答网)  » 电脑/数码/通讯/互联网 » 数据库  » 请教如何将AD中一个组的成员定期导入SQL

请教如何将AD中一个组的成员定期导入SQL


在我的AD里有一个全局的安全性群组包含一些计算机
这个群组里的数据每天都会有变动,想要把这个群组里的计算机名称每天定期导入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
 
Set objConnection = CreateObject("ADODB.Connection")
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.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
Set objExcel = CreateObject("Excel.Application")
    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
   
    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

推荐内容

敬请注意:百科问答网内容来源于网络或民间经验收集,仅供参考。其中有关健康疾病方面的内容请务必咨询专业医生或及时到医院治疗。
关于我们 - 广告服务 - 联系我们
百科问答网 Copyright ©2005 - 2011 www.baikewenda.com,All Rights Reserved
辽ICP备10007180号