Find all the users in a OU if the "Hide from Exchange address list" is ticked. With OU path

Hi,

Find all the users in a OU if the "Hide from Exchange address list" is ticked.
3 checks
Remove the check on all users in an OU
Remove the check in all the the Domain
Get the OU path of all users Checked in the domain.

Regards
Sharath
LVL 11
bsharathAsked:
Who is Participating?
 
Farhan KaziSystems EngineerCommented:
:: ================
:: READ THIS FIRST
:: ================
::  * You need to set 'OUName' variables value inside the script to the actual OU distinguished name or name
::     Like:
::            SET OUName=OU=SALES,DC=TRAINING,DC=com
::     OR
::           SET OUName=SALES
:: * IF you do not set 'OUName' variables value then it will search and modify users 'MSExchHideFromAddressLists' to 'FALSE' in root domain.
:: * Copy and paste following script into notepad and save it with any name having .cmd extension
:: SCRIPT START
@ECHO OFF
SETLOCAL EnableDelayedExpansion

:: You need to set following variables value with actual OU DN or Name
SET OUName=OU=SALES,DC=TRAINING,DC=com

IF EXIST HiddenUserRpt.txt DEL /F /Q HiddenUserRpt.txt
IF EXIST HiddenUser.ldf DEL /F /Q HiddenUser.ldf

IF "%OUName%"=="" (
      DSQuery * -Filter "(&(sAMAccountType=805306368)(MSExchHideFromAddressLists=TRUE))" -L -Limit 0 >HiddenUserRpt.txt
) ELSE (
      ECHO !OUName!|FIND /I "OU=">NUL
      IF NOT ERRORLEVEL 1 (
            DSQuery OU "!OUName!" 2>NUL |FIND /I "OU=" >NUL
            IF NOT ERRORLEVEL 1 (
                  DSQuery OU "!OUName!" >OUTmpVar.txt &SET /P OUDN=<OUTmpVar.txt
            ) ELSE (ECHO Invalid OU distinguished name. &Goto :EndScript)
      )ELSE (
            DSQuery OU -Name "!OUName!" |FIND /I "OU=" >NUL
            IF NOT ERRORLEVEL 1 (
                  DSQuery OU -Name "!OUName!" >OUTmpVar.txt &SET /P OUDN=<OUTmpVar.txt
            ) ELSE (ECHO Invalid OU Name. &Goto :EndScript)      
      )
      DSQuery * !OUDN! -Filter "(&(sAMAccountType=805306368)(MSExchHideFromAddressLists=TRUE))" -L -Limit 0 >HiddenUserRpt.txt)

FOR /F "delims=*" %%u IN ('TYPE HiddenUserRpt.txt') DO ((
      ECHO DN: %%~u
        ECHO changetype: modify
      ECHO replace: MSExchHideFromAddressLists
      ECHO MSExchHideFromAddressLists: FALSE
      ECHO -
      ECHO.)>>HiddenUser.ldf
)
            
IF EXIST HiddenUser.ldf LDIFDE -I -K -F HiddenUser.ldf
:EndScript
IF EXIST OUTmpVar.txt DEL /F /Q OUTmpVar.txt
IF EXIST HiddenUser.ldf DEL /F /Q HiddenUser.ldf
ENDLOCAL
EXIT /B 0
:: *** SCRIPT END ***
0
 
Farhan KaziSystems EngineerCommented:
When you are saying remove check from all domain users then what the use of this >> Remove the check on all users in an OU ?.

So the script will perform following tasks:
>> Find all the users in a OU if the "Hide from Exchange address list" is ticked.
>> Get the OU path of all users Checked in the domain.
>> Remove the check in all the the Domain

Correct me if Im wrong.


0
 
bsharathAuthor Commented:
Yes farhan ...I wanted this options as when required could do for the specific OU alone...
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
bsharathAuthor Commented:
Farhan

If no OU path mentione it will remove the tick from all users in the Domain.
If OU path mentioned then it will remove the tick on any users in the OU.

Will i have the results file with the OU path.?
0
 
Farhan KaziSystems EngineerCommented:
>> If no OU path mentione it will remove the tick from all users in the Domain.
     YES

>> If OU path mentioned then it will remove the tick on any users in the OU.
    YES

>>Will i have the results file with the OU path.?
     It will list all users from Domain/OU inside HiddenUserRpt.txt'
0
 
bsharathAuthor Commented:
Hi Farhan,

If you are free this week end can you help me in some Q...'s please.

Just a reminder on updating your profile...:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.