Share via


Powershell Scrip to validate email address against AD

Question

Friday, February 27, 2015 12:38 PM

Hi

I need help to write a script to validate email address (not email address format) against AD. I have bunch of email addresses in a column on database out of which some are valid and some are not valid (that not valid ones are they moved out of company).

Thanks

Kalyan

Kalyan Akula

All replies (3)

Friday, February 27, 2015 12:54 PM ✅Answered | 1 vote

Just search for the address

get-aduser -Filter "EmailAddress -like '[email protected]'"

If it returns null the address doesn't exist.

¯\(ツ)_/¯


Friday, February 27, 2015 1:02 PM ✅Answered | 1 vote

If your running Exchange it will be much faster to use the Exchange cmdlets

Get-Recipient <email address> 

Email address is not an indexed property in AD, and not required to be unique by AD, so Get-ADUser will have to search all the users looking for the ones that have that email address.  Exchange requires it to be unique and maintains it's own database, and uses it as an index.

[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


Monday, March 9, 2015 7:41 AM

Hi Kalyan,

If there is any update on this issue, please feel free to reply this post directly so we will be notified to follow it up.

If you have any feedback on our support, please click here.

Best Regards,

Anna Wang

Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]