Jay_Jay70
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.Connec tion")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Comman d")
objCommand.ActiveConnectio n = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE" )
objCommand.CommandText = "SELECT name, aDSPath " &_
"FROM 'LDAP://" & objRootDSE.Get("defaultNam ingContext ") & "' WHERE objectClass='group'"
Set objRootDSE = Nothing
objCommand.Properties("Pag e Size") = 1000
objCommand.Properties("Tim eout") = 600
objCommand.Properties("Sea rchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cac he 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.Fie lds("aDSPa th"))
'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
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.Connec
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Comman
objCommand.ActiveConnectio
Set objRootDSE = GetObject("LDAP://RootDSE"
objCommand.CommandText = "SELECT name, aDSPath " &_
"FROM 'LDAP://" & objRootDSE.Get("defaultNam
Set objRootDSE = Nothing
objCommand.Properties("Pag
objCommand.Properties("Tim
objCommand.Properties("Sea
objCommand.Properties("Cac
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.Fie
'WScript.Echo strGroupName & ": Resetting msExchRequireAuthtoSendTo to True"
Err.Clear
objGroup.Put "msExchRequireAuthtoSendTo
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
ASKER
Thanks mate, for multiple groups, cane i add like this "@james, @chris"
is it that syntax?
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.Connec
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Comman
objCommand.ActiveConnectio
Set objRootDSE = GetObject("LDAP://RootDSE"
objCommand.CommandText = "SELECT name, aDSPath " &_
"FROM 'LDAP://" & objRootDSE.Get("defaultNam
Set objRootDSE = Nothing
objCommand.Properties("Pag
objCommand.Properties("Tim
objCommand.Properties("Sea
objCommand.Properties("Cac
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.Fie
'WScript.Echo strGroupName & ": Resetting msExchRequireAuthtoSendTo to True"
Err.Clear
objGroup.Put "msExchRequireAuthtoSendTo
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Champion! Thanks very much for your help - works perfect, and another happy client :)
Pleasure :)
Chris
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.Connec
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Comman
objCommand.ActiveConnectio
Set objRootDSE = GetObject("LDAP://RootDSE"
objCommand.CommandText = "SELECT name, aDSPath " &_
"FROM 'LDAP://" & objRootDSE.Get("defaultNam
Set objRootDSE = Nothing
objCommand.Properties("Pag
objCommand.Properties("Tim
objCommand.Properties("Sea
objCommand.Properties("Cac
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.Fie
'WScript.Echo strGroupName & ": Resetting msExchRequireAuthtoSendTo to True"
Err.Clear
objGroup.Put "msExchRequireAuthtoSendTo
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