Link to home
Start Free TrialLog in
Avatar of ExproChrisDillon
ExproChrisDillon

asked on

VB Script to hide from exchange lists?

I am trying to run the script posted below but getting an error - Type Mismatch, Line 24, Char 5.  Something to do with the IF statement i suspect.  Can anyone help please?
' Change the following line to the OU you want to hide
strOUpath = "****"
 
 ' This will do the target OU and everything under it
Const ADS_SCOPE_BASE = 0
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_BASE 
 
objCommand.CommandText = "SELECT ADsPath, objectClass, objectCategory FROM 'LDAP://" & strOUpath & "'"
Set objRecordSet = objCommand.Execute
 
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    strClass = objRecordSet.Fields("objectClass").Value
    strCategory = objRecordSet.Fields("objectCategory").Value
 
    If strClass = "user" OR strCategory = "person" Then
        strUserPath = objRecordSet.Fields("ADsPath").Value
        Set objUser = GetObject(strUserPath)
        objUser.MSExchHideFromAddressLists = TRUE
        objUser.SetInfo
    End If
 
    objRecordSet.MoveNext
Loop

Open in new window

Avatar of brislane
brislane
Flag of Ireland image

I don't think you can compare strings that way.
Try the following :


if strComp(strClass, "user") OR strComp(strCategory, "person") Then

Open in new window

Avatar of ExproChrisDillon
ExproChrisDillon

ASKER

made suggested change, new error message is type mismatch 'strClass' same line and char number.  Sorry, i'm a bit of an amateur with VB script.
Do a response.write strClass and see what it contains
as i said bit of an amateur with this, can you explain?
ASKER CERTIFIED SOLUTION
Avatar of ExproChrisDillon
ExproChrisDillon

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
Avatar of Chris Dent

It is much better to filter like this during the query rather than within the returned values. In this case that would mean doing:

objCommand.CommandText = "SELECT ADsPath, objectClass, objectCategory FROM 'LDAP://" & _
  strOUpath & "' WHERE objectClass='contact' OR objectCategory='person'"

And considering the query you may just do "WHERE objectCategory='person'" this will return Users and Contacts in the same way as the above.

Then when you come to the loop in the Record Set you would just do:

Do Until objRecordSet.EOF
  strUserPath = objRecordSet.Fields("ADsPath").Value
  Set objUser = GetObject(strUserPath)
  objUser.MSExchHideFromAddressLists = TRUE
  objUser.SetInfo
Loop

The If statements would not be needed because you're only returning the things you're interested in during the search.

Chris