[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

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
0
bsharath
Asked:
bsharath
  • 4
  • 3
1 Solution
 
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
 
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
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now