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