Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Vbs script implements synchronization of users in OU to user groups or distribution groups

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Dim OU (5)

Dim GROUP (5)

OU (1) = ("OU= Shanghai Branch, DC=test,DC=com")

GROUP (1) = ("CN= Shanghai Branch, OU=HAB,DC=test,DC=com")

OU (2) = ("OU= Xiamen Branch, DC=test,DC=com")

GROUP (2) = ("CN= Xiamen Branch, OU=HAB,DC=test,DC=com")

OU (3) = ("OU= Product Management Center, OU= head Office, DC=test,DC=com")

GROUP (3) = ("CN= Product Management Center, OU=HAB,DC=test,DC=com")

OU (4) = ("OU= system maintenance Department, OU= Product Management Center, OU= Corporation, DC=test,DC=com")

GROUP (4) = ("CN= system maintenance, OU=HAB,DC=test,DC=com")

OU (5) = ("OU= Product Management Center I, OU= Product Management Center, OU= head Office, DC=test,DC=com")

GROUP (5) = ("CN= Product Management Center one, OU=HAB,DC=test,DC=com")

For I = 1 to UBound (OU)

CSVDE (OU (I))

When the 'MsgBox "user.txt is exported, the execution begins to add users who are not in OU" & OU (I) & ", distribution group" & GROUP (I) & "to distribution group" & GROUP (I)

OUTG (GROUP (I))

'MsgBox 'starts to delete users from GROUP "& GROUP (I) &", OU "& OU (I) &" from OU "& OU (I) &".

GTUser (GROUP (I))

'MsgBox "starts deleting C:\ user.txt"

Dele

'MsgBox "done"

Next

MsgBox "execution complete"

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 lumped 1 To 1000

If oFSO.FileExists ("C:\ user.txt") = 0 Then

WScript.Sleep 5

Else lump 1000

End If

Next

End Function

'add user that is in OU but not in distribution group

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

The number of members of If (IsEmpty (a) True) Then arrMemberOf=objGroup.GetEx ("member") 'MsgBox objgroup.displayname& "is & UBound (arrMemberOf) + 1 For kryp0 To UBound (arrMemberOf) st=Chr (34) & arrMemberOf (k) & Chr (34) & Chr (13) & Chr (10) & st Next'MsgBox" 222" & objgroup.displayname&st Do While oTF.AtEndOfStreamTrue sLine=oTF.ReadLine If sLine "DN (null) "Then 'MsgBox" sLINE= "& sLine If InStr (st,sLine) Then' MsgBox sLine&" is already in distribution group "& objGroup.displayname&". "Else 'MsgBox sLine&" is not in distribution group "& objGroup.displayname&" & Chr (13) & Chr (10) & st aline=split (sline, "") -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 LoopElse'MsgBox "objGroup.member is empty = & objGroup.member&" a = "& aDo While oTF.AtEndOfStreamTrue sLine=oTF.ReadLine If sLine" DN, (null) "Then 'MsgBox" sLINE= "& sLine aline=split (sline,") -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 LoopEnd If

End Function

'delete the user that is not in OU but in the distribution group

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 is empty strContent=" & strContents Else' MsgBox "user.txt is not empty strContent=" & strContents strContents=objFile.ReadAll objFile.CloseEnd If

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

ObjGroup.Getinfo

'111111of MsgBox & objGroup.displayName

A=objGroup.member

The number of members of If IsEmpty (a) True Then arrMemberOf=objGroup.GetEx ("member") 'MsgBox "is & UBound (arrMemberOf) + 1 For kryp0 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& "contains HAB" Else If InStr (strContents,strMember) Then Else objGroup.PutEx ADS_PROPERTY_DELETE, "member" Array (strMember) objGroup.SetInfo End if End If NextElse 'MsgBox "objGroup.member is empty Do not delete "End If" with execution

End Function

Function Dele

Set oFSO=CreateObject ("scripting.filesystemobject")

Ofso.deletefile "C:\ user.txt"

End Function

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report