# Lookup a DisplayName based on value EmailAddress

**URL:** <https://forums.powershell.org/t/lookup-a-displayname-based-on-value-emailaddress/11354>\
**Category:** PowerShell Help\
**Created:** [September 21, 2018, 12:47pm UTC](https://forums.powershell.org/t/lookup-a-displayname-based-on-value-emailaddress/11354 "2018-09-21T12:47:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [September 21, 2018, 12:47pm UTC](https://forums.powershell.org/t/lookup-a-displayname-based-on-value-emailaddress/11354/1 "2018-09-21T12:47:09Z")

</div>

I have this code to display Users in an OU:

```
Get-ADUser -SearchBase “OU=ServiceAccts,OU=UserAccts,DC=dev,DC=corp,DC=com” -Server[dev.corp.com](http://dev.corp.com)-Credential $creds -Filter * -Properties * |
Select-Object samAccountName,Department,@{ Name = ‘Owner’; Expression = {$_.EmailAddress}},Description,PasswordLastSet
```

…and it works fine but I want to supply another calculated property that then does a lookup for that EmailAddress and displays the displayName of the individual, if exists (because some are DL’s).

How would that be accomplished?

Thanks

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [September 21, 2018, 3:27pm UTC](https://forums.powershell.org/t/lookup-a-displayname-based-on-value-emailaddress/11354/2 "2018-09-21T15:27:29Z")

</div>

You can put any code you want into the Expression script block for a custom property. Whatever that code spits to the pipeline is what goes into the property value. So I suppose you’d do another Get-ADUser call…?

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [September 22, 2018, 2:25am UTC](https://forums.powershell.org/t/lookup-a-displayname-based-on-value-emailaddress/11354/3 "2018-09-22T02:25:40Z")

</div>

Get-ADUser call inside a calculated property for each user will be lil expensive, Isn’t DisplayName an existing property of Domain User ?

---

<div class="post-metadata">

**Author:** ![sconstantinou](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sconstantinou/32/287_2.png) [@sconstantinou](https://forums.powershell.org/u/sconstantinou)\
**Post date:** [September 22, 2018, 8:54am UTC](https://forums.powershell.org/t/lookup-a-displayname-based-on-value-emailaddress/11354/4 "2018-09-22T08:54:46Z")

</div>

By using the below you can get what you need.There is no need for any expression. I don’t understand the need of using expression on EmailAddress property, other than just renaming the property.

```
Get-ADUser -SearchBase "OU=ServiceAccts,OU=UserAccts,DC=dev,DC=corp,DC=com" -Server dev.corp.com -Credential $creds -Filter * -Properties * |
    Select-Object DisplayName,samAccountName,Department,@{ Name = 'Owner'; Expression = {$_.EmailAddress}},Description,PasswordLastSet
```

More properly and for faster results instead of taking all properties of the users and selecting the one you need, It should be better to get only those properties. Check below:

```
Get-ADUser -SearchBase "OU=ServiceAccts,OU=UserAccts,DC=dev,DC=corp,DC=com" -Server dev.corp.com -Credential $creds -Filter * -Properties samAccountName,DisplayName,Departement,EmailAddress,Description,PasswordLastSet |
    Select-Object samAccountName,Department,EmailAddress,Description,PasswordLastSet
```

I have measured the commands and is about 10 times faster.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/lookup-a-displayname-based-on-value-emailaddress/11354/5 "2024-05-16T20:34:22Z")

</div>


