Advertisement

10.03.2008 at 08:40AM PDT, ID: 23785403
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

Script that removes all groups from all users in the file. Need to be changed.

Asked by bsharath in VB Script, Programming Languages

Tags: ,

Hi,

Script that removes all groups from all users in the file. Need to be changed.

1. I want a way that i can mention in the script if all security groups have to be removed or Distribution groups have to be removed.
So all users in the file get there Distribution groups removed or Security groups removed. Any one to be removed.

Regards
SharathStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
'====================
If Right(LCase(WScript.FullName), 11) = "wscript.exe" Then
      Set objShell = CreateObject("WScript.Shell")
      objShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
      Set objShell = Nothing
      WScript.Quit
End If
 
strInputFile = "Users.txt" ' must be login names
strOutputFile = "Results.CSV"
 
Const ADS_PROPERTY_APPEND = 3
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
 
 ' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
 
strPrimaryGroup = "cn=Domain Users,cn=Users," & strDNSDomain   ' e.g. cn=SalesGroup,ou=Sales,dc=rallencorp,dc=com
Set objPGroup = GetObject("LDAP://" & strPrimaryGroup)
 
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
strDetails = "USERS REMOVED FROM GROUPS"
While Not objInputFile.AtEndOfStream
      strUserName = objInputFile.ReadLine
      strDetails = strDetails & VbCrLf & strUserName
      strFilter = "(&(objectCategory=person)(objectClass=user)(samAccountName=" & strUserName & "))"
      'strFilter = "(&(objectClass=computer)(cn=" & strComputer & "))"
      
      ' Comma delimited list of attribute values to retrieve.
      'strAttributes = "sAMAccountName,cn"
      strAttributes = "ADsPath"
      
      ' Construct the LDAP syntax query.
      strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
      adoCommand.CommandText = strQuery
      adoCommand.Properties("Page Size") = 100
      adoCommand.Properties("Timeout") = 30
      adoCommand.Properties("Cache Results") = False
      
      ' Run the query.
      Set adoRecordset = adoCommand.Execute
       
      ' Enumerate the resulting recordset.
      Do Until adoRecordset.EOF
            'WScript.Echo "Proccessing: " & adoRecordset.Fields("ADsPath").Value
          ' Retrieve values and display.
            Set objUser = GetObject(adoRecordset.Fields("ADsPath").Value)
 
            strResults = ""
            strGroups = ""
            WScript.Echo ""
 
            objPGroup.GetInfoEx Array("primaryGroupToken"), 0
            If objPGroup.Get("primaryGroupToken") = objUser.Get("primaryGroupID") Then
                  WScript.Echo "Primary group for user already set to " & strPrimaryGroup
            Else
                  WScript.Echo "Current Primary Group: " & objUser.Get("primaryGroupID")
                  On Error Resume Next ' Just to suppress errors if the user is already in the group.
                  objPGroup.Add adoRecordset.Fields("ADsPath").Value
                  On Error Goto 0
                  objUser.Put "primaryGroupID", objPGroup.Get("primaryGroupToken")
                  objUser.SetInfo
                  WScript.Echo "Primary group for user " & Replace(objUser.CN, "CN=", "") & " changed to " & strPrimaryGroup
                  'Refresh the current user connection
                  Set objUser = Nothing
                  WScript.Sleep 1000
                  Set objUser = GetObject(adoRecordset.Fields("ADsPath").Value)
            End If
            
            GetMemberOfNames objUser
            
            strResults = Replace(objUser.Name, "CN=", "") & " was removed from the following groups: "
            arrGroups = Split(strGroups, VbCrLf)
            For intCount = LBound(arrGroups) To UBound(arrGroups)
                  strDetails = strDetails & "," & arrGroups(intCount)
                  If strResults = "" Then
                        strResults = arrGroups(intCount)
                  Else
                        strResults = strResults & VbCrLf & arrGroups(intCount)
                  End If
            Next
      
            WScript.Echo strResults
            
            Set objUser = Nothing
            adoRecordset.MoveNext
      Loop
 
      ' Clean up.
      adoRecordset.Close
      Set adoRecordset = Nothing
Wend
 
adoConnection.Close
 
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing
 
WScript.Echo "Done"
MsgBox "Done"
 
Sub GetMemberOfNames(objObjectToCheck)
      ' This function can get caught in a loop if there is a circular
      ' group membership.  There is a method of using a Dictionary object
      ' here: http://www.rlmueller.net/MemberOf.htm
      ' which checks if the group has been used before.
      
      ' Retrieve ALL of the user groups that a user is a member of
      On Error Resume Next
      objMemberOf = objObjectToCheck.GetEx("MemberOf")
      If Err.Number = 0 Then
            On Error GoTo 0
            For Each objGroup in objMemberOf
                  If LCase(objGroup) <> LCase(strPrimaryGroup) Then
                        strGroupName = Left(Mid(objGroup, InStr(objGroup, "CN=") + 3),InStr(Mid(objGroup, InStr(objGroup, "CN=") + 3), ",") - 1)
                        If strGroups = "" Then
                              strGroups = strGroupName
                        Else
                              strGroups = strGroups & VbCrLf & strGroupName
                        End If
                        Set objTheGroup = GetObject("LDAP://" & objGroup)
                        objTheGroup.Remove(objObjectToCheck.AdSPath)
                  End If
            Next
      Else
            Err.Clear
            On Error GoTo 0
      End If
End Sub
'====================
[+][-]10.04.2008 at 06:40AM PDT, ID: 22640799

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.04.2008 at 06:47AM PDT, ID: 22640820

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.04.2008 at 07:27AM PDT, ID: 22640983

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.04.2008 at 07:43AM PDT, ID: 22641111

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.04.2008 at 07:46AM PDT, ID: 22641145

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.04.2008 at 07:57AM PDT, ID: 22641190

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.04.2008 at 02:30PM PDT, ID: 22642329

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Script, Programming Languages
Tags: Script, vbs
Sign Up Now!
Solution Provided By: si_shamil
Participating Experts: 1
Solution Grade: A
 
 
[+][-]10.05.2008 at 01:44AM PDT, ID: 22643805

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906