best business builder

Get Email Address From SAMACCOUNTNAME

This Active Directory PowerShell Module code will show you how to the primary SMTP address of users using their SAMACCOUNTNAME.

In this scenario, You have a list of users’ SAMACCOUNT name login details and you want to know \ get their email address.

In this case, My Users.txt file has a list of users with which looks like this:

User1
User2
User3

The code looks like:

$x = Get-Content .\users.txt

$x | Foreach {Get-ADUser -Filter {UserPrincipalName -like $_ } -Properties *|Select SAMAccountName, emailaddress} | Export-Csv USERS.csv

The code will export the email address and SAMaccountName of the users to a .CSV file.

Got a project that needs expert IT support?

From Linux and Microsoft Server to VMware, networking, and more, our team at CR Tech is here to help.

Get personalized support today and ensure your systems are running at peak performance or make sure that your project turns out to be a successful one!

CONTACT US NOW
best vpn deal