Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

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
Avatar of Speshalyst
Speshalyst
Flag of India image

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..

:: ===============
:: 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 ***
Avatar of bsharath

ASKER

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.
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.
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?
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.
>> "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 "@"
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
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
Did you verified the email address inside User Properties -> General -> E-mail in ADS?
Yes the email id's are there in user>properties> General > Email in ADS.
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 ***
I get this.

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


No results file....
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

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