成都网站建设设计

将想法与焦点和您一起共享

vbs脚本实现将OU中用户同步到用户组或通讯组-创新互联

Dim OU(5)
Dim GROUP(5)
OU(1)=("OU=上海分公司,DC=test,DC=com")
GROUP(1)=("CN=上海分公司,OU=HAB,DC=test,DC=com")
OU(2)=("OU=厦门分公司,DC=test,DC=com")
GROUP(2)=("CN=厦门分公司,OU=HAB,DC=test,DC=com")
OU(3)=("OU=产品管理中心,OU=总公司,DC=test,DC=com")
GROUP(3)=("CN=产品管理中心,OU=HAB,DC=test,DC=com")

10年积累的成都网站设计、成都网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有阿拉善盟免费网站建设让你可以放心的选择与我们合作。

OU(4)=("OU=系统维护部,OU=产品管理中心,OU=总公司,DC=test,DC=com")
GROUP(4)=("CN=系统维护部,OU=HAB,DC=test,DC=com")

OU(5)=("OU=产品管理中心一部,OU=产品管理中心,OU=总公司,DC=test,DC=com")
GROUP(5)=("CN=产品管理中心一部,OU=HAB,DC=test,DC=com")

for i= 1 to UBound(OU)
CSVDE(OU(i))
'MsgBox "user.txt导出完毕,开始执行将OU"&OU(i)&"中有,通讯组"&GROUP(i)&"中没有的用户添加进通讯组"&GROUP(i)
OUTG(GROUP(i))
'MsgBox "开始执行将GROUP"&GROUP(i)&"中有,OU"&OU(i)&"中没有的用户从OU"&OU(i)&"中删除"
GTUser(GROUP(i))
'MsgBox "开始删除C:\user.txt"
Dele
'MsgBox"done"
Next
MsgBox "执行完毕"

Function CSVDE(OU)
Set oFSO=CreateObject("scripting.filesystemobject")
Set ws=CreateObject("WScript.Shell")
ws.run("csvde -f C:\user.txt -p onelevel -r objectclass=user -l dn -d "&OU)
For l=1 To 1000
if oFSO.FileExists("C:\user.txt")=0 Then
WScript.Sleep 5
else l=1000
End If
Next
End Function

'添加OU里有但通讯组里没有的user
Function OUTG(GROUP)
'On error resume Next
Const ForReading= 1
Const ADS_PROPERTY_APPEND=3
Set oFSO= CreateObject("scripting.filesystemobject")
Set oTF= oFSO.OpenTextFile("C:\user.txt",ForReading,True)
Set objGroup= GetObject("LDAP://"&GROUP)

a=objGroup.member

If (IsEmpty(a)<>True) Then

    arrMemberOf=objGroup.GetEx("member")

    'MsgBox objgroup.displayname&"成员个数为"&UBound(arrMemberOf)+1 

    For k=0 To UBound(arrMemberOf) 

        st=Chr(34)&arrMemberOf(k)&Chr(34)&Chr(13)&Chr(10)& st
    Next
    'MsgBox "222"&objgroup.displayname&st

    Do While oTF.AtEndOfStream<>True
        sLine=oTF.ReadLine
        If  sLine<>"DN,(null)" Then 
            'MsgBox "sLINE="&sLine
            If InStr(st,sLine) Then
            '   MsgBox  sLine&"已经在通讯组"&objGroup.displayname&"中了"
            Else
            '   MsgBox  sLine&"不在通讯组"&objGroup.displayname&"中"&Chr(13)&Chr(10)&st
                aline=split(sline,"",-1,1)
                Namel=Trim(aLine(0))
                Name2=left(Namel,len(Namel)-1)
                Name3=right(Name2,len(Name2)-1)
            '   MsgBox  Name3
                objGroup.PutEx ADS_PROPERTY_APPEND,"member",Array(Name3)
                objGroup.Setinfo
            End If
        Else
        End If  
    Loop
Else

'MsgBox "objGroup.member为空="&objGroup.member&"a="&a

Do While oTF.AtEndOfStream<>True
        sLine=oTF.ReadLine
        If  sLine<>"DN,(null)" Then 
            'MsgBox "sLINE="&sLine
                aline=split(sline,"",-1,1)
                Namel=Trim(aLine(0))
                Name2=left(Namel,len(Namel)-1)
                Name3=right(Name2,len(Name2)-1)
                'MsgBox Name3
                objGroup.PutEx ADS_PROPERTY_APPEND,"member",Array(Name3)
                objGroup.Setinfo

        Else
        End If  
    Loop

End If

End Function

'删除OU里没有但通讯组里有的user
Function GTUser(GROUP)
'On error resume Next
Const ForReading=1
Const ADS_PROPERTY_DELETE=4
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.OpenTextFile("C:\user.txt",ForReading)

If objFile.AtEndOfStream=True Then
        strContents=0
        'MsgBox "user.txt是空的strContent="&strContents
    Else 
        'MsgBox "user.txt不是空的strContent="&strContents
        strContents=objFile.ReadAll
        objFile.Close
End If

Set objGroup=GetObject("LDAP://"&GROUP)
objGroup.Getinfo

'MsgBox "111"&objGroup.displayName
a=objGroup.member

If IsEmpty  (a)<>True Then

        arrMemberOf=objGroup.GetEx("member")

        'MsgBox "成员个数为"&UBound(arrMemberOf)+1 

            For k=0 To UBound(arrMemberOf) 

                st=arrMemberOf(k) &Chr(13)&Chr(10)& st

            Next

        'MsgBox st

        For Each strMember in arrMemberOf
            If InStr(strMember,"HAB") Then
                    'MsgBox strMember&"包含HAB"
                Else
                    If InStr(strContents,strMember) Then
                        Else
                        objGroup.PutEx ADS_PROPERTY_DELETE,"member",Array(strMember)
                        objGroup.SetInfo
                    End if
            End If

        Next

Else
    'MsgBox "objGroup.member空,不要用执行删除"
End If

End Function

Function Dele
Set oFSO=CreateObject("scripting.filesystemobject")
ofso.deletefile"C:\user.txt"
End Function

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前文章:vbs脚本实现将OU中用户同步到用户组或通讯组-创新互联
转载来源:http://chengdu.cdxwcx.cn/article/esjcj.html