Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB Script to hide from exchange lists?

Posted on 2009-04-10
6
275 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:ExproChrisDillon
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:brislane
ID: 24116439
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

0
 

Author Comment

by:ExproChrisDillon
ID: 24116665
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.
0
 
LVL 2

Expert Comment

by:brislane
ID: 24116712
Do a response.write strClass and see what it contains
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:ExproChrisDillon
ID: 24128519
as i said bit of an amateur with this, can you explain?
0
 

Accepted Solution

by:
ExproChrisDillon earned 0 total points
ID: 24137854
Got the answer from mcpp661 -

mcpp661
04.13.2009 at 04:10PM IST, ID: 24130354
Here's what I use, it works like a champ for me.
Option Explicit
On Error Resume Next
Dim strOUpath, strClass, strCategory, strUserPath
Dim objConnection, objCommand, objRecordSet, objUser
 
 ' Change the following line to the OU you want to hide
strOUpath = "ou=<ou_name_here>,dc=<domain_component_name_here>,dc=<domain_component_name_here>"
 
 ' This will do the target OU and everything under it
Const ADS_SCOPE_SUBTREE = 2
 
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_SUBTREE 
 
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 = "contact" OR strCategory = "person" Then
        strUserPath = objRecordSet.Fields("ADsPath").Value
        Set objUser = GetObject(strUserPath)
        objUser.MSExchHideFromAddressLists = TRUE
        objUser.SetInfo
    End If
 
    objRecordSet.MoveNext
Loop
 
Set objConnection = Nothing
Set objCommand = Nothing
Set objRecordSet = Nothing
Set objUser = Nothing
 
WScript.Quit

Open in new window

0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 24156847

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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we show how to create a User Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Mailb…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question