Link to home
Start Free TrialLog in
Avatar of Jay_Jay70
Jay_Jay70Flag for Australia

asked on

Continued Question Re: Script... Chris! I'm back!

Hey Mate,

in regards to that script you helped me with last week, i need to exempt just one group from it! Is there a way to do it? Group is say    @james

Here is the code you gave me

Option Explicit

Const ADS_SCOPE_SUBTREE = 2

Dim objConnection, objCommand, objRecordSet, objRootDSE, objGroup
Dim strGroupName

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT name, aDSPath " &_
     "FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & "' WHERE objectClass='group'"
Set objRootDSE = Nothing

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
     On Error Resume Next
     strGroupName = objRecordSet.Fields("name")
     If Left(strGroupName, 1) = "@" Then
          Set objGroup = GetObject(objRecordSet.Fields("aDSPath"))
          'WScript.Echo strGroupName & ": Resetting msExchRequireAuthtoSendTo to True"
          Err.Clear
           objGroup.Put "msExchRequireAuthtoSendTo", True
           objGroup.SetInfo
          If Err.Number <> 0 Then
               WScript.Echo strGroupName & ": Failed; " & Err.Description
          End If
          Set objGroup = Nothing
     End If

     On Error Goto 0
     objRecordSet.MoveNext
Wend

objConnection.Close

Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing

Thanks again!

J
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image


Hey J,

Yep, dead easy :)

Add the Group Name to the EXCLUDED_GROUP constant; it's not case sensitive or anything; @james is added as the example.


Option Explicit

Const EXCLUDED_GROUP = "@james"

Const ADS_SCOPE_SUBTREE = 2

Dim objConnection, objCommand, objRecordSet, objRootDSE, objGroup
Dim strGroupName

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT name, aDSPath " &_
      "FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & "' WHERE objectClass='group'"
Set objRootDSE = Nothing

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute
      
While Not objRecordSet.EOF
      On Error Resume Next
      strGroupName = objRecordSet.Fields("name")
      If Left(strGroupName, 1) = "@" And LCase(strGroupName) <> LCase(EXCLUDED_GROUP) Then
            Set objGroup = GetObject(objRecordSet.Fields("aDSPath"))
            'WScript.Echo strGroupName & ": Resetting msExchRequireAuthtoSendTo to True"
            Err.Clear
            objGroup.Put "msExchRequireAuthtoSendTo", True
            objGroup.SetInfo
            If Err.Number <> 0 Then
                  WScript.Echo strGroupName & ": Failed; " & Err.Description
            End If
            Set objGroup = Nothing
      End If

      On Error Goto 0
      objRecordSet.MoveNext
Wend

objConnection.Close

Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Avatar of Jay_Jay70

ASKER

Thanks mate, for multiple groups, cane i add like this   "@james, @chris"

is it that syntax?

Nope; that one doesn't at all. This one does though. All you need to do is add the groups you want to avoid into this:

arrExcludedGroups = Array("@james", "@chris")

Each should be enclosed in quotes, and the list is comma seperated. You can just have one in there if you like; but don't remove the "Array(" bit or it will get upset ;)

Chris



Option Explicit

Dim arrExcludedGroups
arrExcludedGroups = Array("@james", "@chris")

Const ADS_SCOPE_SUBTREE = 2

Dim objConnection, objCommand, objRecordSet, objRootDSE, objGroup
Dim strGroupName, strGroup
Dim booResetAuth

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT name, aDSPath " &_
      "FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & "' WHERE objectClass='group'"
Set objRootDSE = Nothing

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
      On Error Resume Next
      strGroupName = objRecordSet.Fields("name")
      If Left(strGroupName, 1) = "@" Then

            booResetAuth = True
            For Each strGroup in arrExcludedGroups
                  If LCase(strGroupName) = LCase(strGroup) Then
                        booResetAuth = False
                  End If
            Next

            Set objGroup = GetObject(objRecordSet.Fields("aDSPath"))
            'WScript.Echo strGroupName & ": Resetting msExchRequireAuthtoSendTo to True"
            Err.Clear
            objGroup.Put "msExchRequireAuthtoSendTo", True
            objGroup.SetInfo
            If Err.Number <> 0 Then
                  WScript.Echo strGroupName & ": Failed; " & Err.Description
            End If
            Set objGroup = Nothing
      End If

      On Error Goto 0
      objRecordSet.MoveNext
Wend

objConnection.Close

Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Champion! Thanks very much for your help - works perfect, and another happy client :)

Pleasure :)

Chris