Check the NT login and email id with ADS

Hi,

I have a excel sheet and a txt file which has all the NT logins and Email id's of all users in the company.I dout that some are wrong.Is there a way to cross check these details with ads and list all data which is not found.

NT login    Email ID
Sharathr    sharath.reddy@plc.com

Regards
Sharath
LVL 11
bsharathAsked:
Who is Participating?
 
Farhan KaziSystems EngineerCommented:
Try this:

:: ===============
:: READ THIS FIRST
:: ===============
:: * This script MailIDs.txt file on C: drive root, from where it will pick users SAM ID of and email address.
::       'MailIDs.txt' file should be in following format (space separated):
::       <NTUserID> <Email Address>      
::      Like:
::       FKazi      fkazi@somedomain.com
:: * Successful run will generate "MailMismatch.txt" file on C: drive root.
:: * Copy and paste following script in notepad and save it with any name having .cmd extension.
::
:: *** SCRIPT START ***
@Echo Off
SETLOCAL EnableDelayedExpansion

IF NOT EXIST C:\MailIDs.txt Goto ShowErr
FOR %%R IN (C:\MailIDs.txt) Do IF %%~zR EQU 0 Goto ShowErr
IF EXIST C:\MailMismatch.txt DEL /F /Q C:\MailMismatch.txt

FOR /F "Tokens=1-2" %%i IN ('Type C:\MailIDs.txt') Do (
    Echo Processing: %%i
      SET Qry=DSQuery * -Filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%%i*))" -Attr Mail -L ^| Find "@"
      FOR /F "Tokens=1" %%x IN ('!Qry!') Do (
         Echo %%j|Find /I "%%x" >NUL
       IF ErrorLevel 1 Echo %%i: Email Mismatch >>C:\MailMismatch.txt
      )
)
Goto EndScript
:ShowErr
Echo 'MailIDs.txt' file does not exist or file is empty!
:EndScript
ENDLOCAL
:: *** SCRIPT END ***
0
 
speshalystCommented:
If you are familiar with LDAP queries, you could write one yourself to get a list of MAIL ENABLED users from the AD into an excel sheet.

Once you complete that, you can use the EXACT() funtion in excel to verify if they match..

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Farhan KaziSystems EngineerCommented:
:: ===============
:: READ THIS FIRST
:: ===============
:: * This script MailIDs.txt file on C: drive root, from where it will pick users SAM ID of and email address.
::       'MailIDs.txt' file should be in following format (space separated):
::       <NTUserID> <Email Address>      
::      Like:
::       FKazi      fkazi@somedomain.com
:: * Successful run will generate "MailMismatch.txt" file on C: drive root.
:: * Copy and paste following script in notepad and save it with any name having .cmd extension.
::
:: *** SCRIPT START ***
@Echo Off
SETLOCAL EnableDelayedExpansion

IF NOT EXIST C:\MailIDs.txt Goto ShowErr
FOR %%R IN (C:\MailIDs.txt) Do IF %%~zR EQU 0 Goto ShowErr
IF EXIST C:\MailMismatch.txt DEL /F /Q C:\MailMismatch.txt

FOR /F "Tokens=1-2" %%i IN ('Type C:\MailIDs.txt') Do (
    Echo Processing: %%i
      SET Qry=DSQuery * DomainRoot -Filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%%i*))" -Attr Mail -L ^| Find "@"
      FOR /F "Tokens=1" %%x IN ('!Qry!') Do (
            IF /I NOT "%%j"=="%%x" Echo %%i: Email Mismatch >>C:\MailMismatch.txt
      )
)
Goto EndScript
:ShowErr
Echo 'MailIDs.txt' file does not exist or file is empty!
:EndScript
ENDLOCAL
:: *** SCRIPT END ***
0
 
bsharathAuthor Commented:
Farhan i get this.

Processing: BramhaR
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
Processing: KumaresanV
The process cannot access the file because it is being used by another process.
0
 
Farhan KaziSystems EngineerCommented:
I think there is something wrong with the system where you are running this script!
Restart the system and and then check. Also check this script on some other pc's.
0
 
bsharathAuthor Commented:
Ok farhan.

I tried in 5 machines and in one machine i got some thing different.

I got this in the results file.

HariKr: Email Mismatch
HariKr: Email Mismatch
HariKr: Email Mismatch
Jayal: Email Mismatch
Jayal: Email Mismatch
HariSh: Email Mismatch
HariSh: Email Mismatch
HariSh: Email Mismatch
HariSh: Email Mismatch
BalaSu: Email Mismatch
BalaSu: Email Mismatch
BalaSu: Email Mismatch
BalaSu: Email Mismatch
BalaSu: Email Mismatch
BalaSu: Email Mismatch
VijayaK: Email Mismatch
VijayaK: Email Mismatch
VijayaK: Email Mismatch
VijayaK: Email Mismatch
VijayaK: Email Mismatch
VinothK: Email Mismatch

Many names are duplicate and their email id's are correct.

How does this script check

Sharathr  Sharath.reddy@plc.com

Should there be onlt 1 space between the nt login and email id?
0
 
bsharathAuthor Commented:
I can remove the duplicates in the excel but
I get the results like this.

RajeshS       Email Mismatch
Rajeshse       Email Mismatch
RajeshV       Email Mismatch
RameshK       Email Mismatch
RameshS       Email Mismatch

But when i check the ads or my file the email id's are correct.
0
 
Farhan KaziSystems EngineerCommented:
>> "Should there be onlt 1 space between the nt login and email id?" Correct

Above script will compare email address that you have given inside User Properties -> General -> E-mail in AD.

Kindly apply following commands and post the result.

Click Start -> Run -> Cmd.exe

DSQuery * DomainRoot -Filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=HariKr))" -Attr Mail -L  | Find "@"

DSQuery * DomainRoot -Filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=VijayaK))" -Attr Mail -L  | Find "@"
0
 
bsharathAuthor Commented:
I get this.

C:\>DSQuery * DomainRoot -Filter "(&(objectCategory=Person)(objectClass=User)(sA
MAccountName=HariKr))" -Attr Mail -L  | Find "@"
Hari.Krishna@plc.com

C:\>DSQuery * DomainRoot -Filter "(&(objectCategory=Person)(objectClass=User)(sA
MAccountName=VijayaK))" -Attr Mail -L  | Find "@"
Vijaya.Krishnamoorthy@plc.com
0
 
bsharathAuthor Commented:
I have tried with single space.
I only have this in the file
BramhaR Bramha.Reddy@plc.com
KumaresanV Kumaresan.Vaiyapuri@plc.com
SusantaK Susanta.Kumar@plc.com
SureshK Suresh.Kandan@plc.com
SivaP Siva.Prasad@plc.com
Thanak Thanasekar.Kasi@plc.com
Umag Uma.Maheswari@plc.com

I get this

BramhaR: Email Mismatch
KumaresanV: Email Mismatch
SusantaK: Email Mismatch
SureshK: Email Mismatch
SivaP: Email Mismatch
Thanak: Email Mismatch
Umag: Email Mismatch
0
 
Farhan KaziSystems EngineerCommented:
Did you verified the email address inside User Properties -> General -> E-mail in ADS?
0
 
bsharathAuthor Commented:
Yes the email id's are there in user>properties> General > Email in ADS.
0
 
Farhan KaziSystems EngineerCommented:
Run following script and post the results.

:: ===============
:: READ THIS FIRST
:: ===============
:: * This script MailIDs.txt file on C: drive root, from where it will pick users SAM ID of and email address.
::       'MailIDs.txt' file should be in following format (space separated):
::       <NTUserID> <Email Address>      
::      Like:
::       FKazi      fkazi@somedomain.com
:: * Successful run will generate "MailMismatch.txt" file on C: drive root.
:: * Copy and paste following script in notepad and save it with any name having .cmd extension.
::
:: *** SCRIPT START ***
@Echo Off
SETLOCAL EnableDelayedExpansion

IF NOT EXIST C:\MailIDs.txt Goto ShowErr
FOR %%R IN (C:\MailIDs.txt) Do IF %%~zR EQU 0 Goto ShowErr
IF EXIST C:\MailMismatch.txt DEL /F /Q C:\MailMismatch.txt

FOR /F "Tokens=1-2" %%i IN ('Type C:\MailIDs.txt') Do (
      SET Qry=DSQuery * -Filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%%i*))" -Attr Mail -L ^| Find "@"
      FOR /F "Tokens=1" %%x IN ('!Qry!') Do (Echo %%i : [%%j][%%x])
)
Goto EndScript
:ShowErr
Echo 'MailIDs.txt' file does not exist or file is empty!
:EndScript
ENDLOCAL
:: *** SCRIPT END ***
0
 
bsharathAuthor Commented:
I get this.

BramhaR : [Bramha.eddy@plc.com][Bramha.Reddy@plc.com]
KumaresanV : [Kumaresan.Vaiyapuri@plc.com][Kumaresan.Vaiyapuri@plc.com


No results file....
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.