0

is it possible to get corresponding email attribute from object property of user

$user = "domainname/someOU/someOU/username"
    Get-ADUser -Filter { CN -eq $user } -Properties *| Select displayname,emailaddress
tictactoe
  • 11
  • 2
  • 6

2 Answers2

1

Email Address is store in the property mail. Canonical name is stored in CanonicalName

-Filter * returns all of the properties on the object. Select-Object is returns only the selected properties. So -filter * | Select-Object * would show you every property that you can return with the cmdlet, where normally the default formatting shows only a few. -filter * | Format-List would accomplish the same goal.

In your particular case, you only want a few properties. So not using -filter * and only choosing the properties you want will be more efficient.

Get-ADUser username -Properties mail,CanonicalName |
    Select-Object displayname,mail,CanonicalName
BenH
  • 9,766
  • 1
  • 22
  • 35
-1

On my company's domain, this is how I would get a user's info that you asked for:

$UserInfo = Get-ADUser -Filter "Name -like '*users_name*'" | select Givenname,UserPrincipalName
$UserInfo.Givenname           <-- this displays their name
$UserInfo.UserPrincipalName   <-- this displays their email address

If the property names are different for some reason, you can just do

Get-ADUser -Filter "Name -like '*users_name*'" | select *

to view all of the available properties and their values for whoever you are searching for.

cet51
  • 1,196
  • 2
  • 11
  • 29
  • Yes we can easy query this using displayname but how about the canonical name can you query that.. – tictactoe Jul 21 '17 at 19:46
  • I have not a clue :) I would suggest including that in your original post for clarity of what you want – cet51 Jul 21 '17 at 19:56
  • 1
    @CoryEtmund That was part of the original request. perhaps not in as many words. – Matt Jul 21 '17 at 20:09
  • UPN is not necessarily the same as mail address. It's convenient when it is though. – BenH Jul 21 '17 at 20:26