Advertisement
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.
Your Input Matters 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! |
||
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
'====================
|