To get username and email in Active Directory accounts using PowerShell, can be done easily if AD Powershell Modules cmdlets is loaded on the system.
Check out this link if PowerShell AD module is not loaded:
Codes below will get all user accounts in Active Directory.
Code below will display Name, UserPrincipalName and EmailAddress.
Get-ADUser -Filter * | FT Name,UserPrincipalName,EmailAddress -AutoSize
Name is the user account complete name (First name, Surname).
UPN or UserPrincipalName is the domain account name for logon purposes.
Email Address the email account address set on the user account property.
Code below will display UserName, Email Address and PasswordLastSet (if PasswordLastSet data is available it will be displayed)
Get-ADUser -Properties * -Filter * | FT Name,EmailAddress,PasswordLastSet -AutoSize
Display user accounts which email address has set on its property.
Will only display users with email address set on its account.
Get-ADUser -Properties EmailAddress,Name -Filter 'EmailAddress -ne "x"' | FT Name,EmailAddress -AutoSize
To query or get data for a single user need to include the -Identity parameter followed by the username.
Get-ADUser -Properties * -Identity CaptainUser | FT EmailAddress,PasswordLastSet -AutoSize
Cheers..Hope it helps!!!