Home » PowerShell » Get AdUser Display Name using PowerShell

Get AdUser Display Name using PowerShell

The Get-AdUser cmdlet in PowerShell retrieves the active directory user objects. It has DisplayName property that retrieves the aduser display name in Active Directory.

DisplayName attribute of the Get-AdUser cmdlet is automatically generated based on the ‘GivenName’ (first name) and ‘SurName’ ( last name) attributes. It can be customized based on the requirement to include additional information.

In this article, we will discuss how to use the DisplayName attribute to get aduser display name in PowerShell.

Get AdUser Display Name

Use the Get-AdUser cmdlet in PowerShell to get the display name of the active directory user. It retrieves all properties including displayname.

Get-AdUser -Identity Toms -Properties * | Select DisplayName

In the above PowerShell script, the Get-AdUser cmdlet uses the Identity parameter to specify the username for the user to retrieve the user information.

The properties * parameter retrieves all properties including displayname.

It passes the output through the pipeline operator to the Select cmdlet to select the DisplayName of the aduser.

The output of the above PowerShell script to get-aduser display name is:

Get AdUser Display Name
Get AdUser Display Name

Get AdUser Filter DisplayName like the specified name

The Get-AdUser cmdlet in PowerShell has a Filter parameter to specify the condition to filter displayname like the specified display name of the aduser.

 Get-AdUser  -Filter {DisplayName -like "Tom*"} -Properties * | Select DisplayName

In the above PowerShell script of the Get-AdUser example, cmdlet uses the filter parameter to filter displayname like the specified “Tom*”.

It uses the Properties * to retrieve all properties including displayname and pipeline the aduser information to the Select cmdlet to select the user’s display name.

The output of the above PowerShell script retrieves the aduser displayname like the provided user name and shows aduser displayname on the console.

PS C:\> Get-AdUser  -Filter {DisplayName -like "Tom*"} -Properties * | Select DisplayName

DisplayName
-----------
Tom Smith

Get AdUser DisplayName from SamAccountName

The Get-AdUser cmdlet has a SamAccountName attribute that contains the user logon name and can be used to retrieve aduser displayname from samaccountname.

The following PowerShell script uses the Get-AdUser cmdlet to retrieve the aduser from samaccountname. It uses the Properties * parameter to retrieve additional user properties including the displayname.

Get-AdUser  -Identity Toms -Properties * | Select DisplayName, SamAccountname

The output of the above PowerShell script gets aduser displayname from samaccountname. The select command selects displayname, and samaccountname and outputs it on the console.

PS C:\> Get-AdUser  -Identity Toms -Properties * | Select DisplayName, SamAccountname

DisplayName SamAccountname
----------- --------------
Tom Smith   toms

Get AdUser Where DisplayName like

The Get-AdUser cmdlet in PowerShell with the Where condition can be used to filter the results based on specified conditions.

To get aduser where displayname like Nath, run the following PowerShell script.

Get-AdUser -Filter * -Properties * | Where {$_.DisplayName -like 'Natha*'} | Select DisplayName, SamAccountName

In the above PowerShell script, the Get-AdUser cmdlet uses the Filter and Properties * parameters to select all active directory users and their properties.

It passes the output through the pipeline operator to the Where command which checks if the aduser displayname is like ‘Nath*’ and retrieves the user’s displayname and samaccountname.

The output of the above PowerShell script to get aduser where displayname like is:

PS C:\> Get-AdUser -Filter * -Properties * | Where {$_.DisplayName -like 'natha*'} | Select DisplayName, SamAccountName

DisplayName SamAccountName
----------- --------------
Nathan Tim  nathan

Get AdUser DisplayName Empty in Active Directory

To get all the aduser having their displayname empty, run the following PowerShell script.

 Get-AdUser -Filter * -Properties * | Where {$_.DisplayName -like ''} | Select DisplayName, SamAccountName

In the above PowerShell script, the Get-AdUser cmdlet retrieves all the active directory users and passes them through the pipeline operator to check if the aduser displayname is empty and select the displayname and samaccountname of the aduser.

The output of the script to get aduser having displayname empty is:

PS C:\> Get-AdUser -Filter * -Properties * | Where {$_.DisplayName -like ''} | Select DisplayName, SamAccountName

DisplayName SamAccountName
-----------           --------------
                        Guest
                        krbtgt
                        gary.waugh

PowerShell Get AdUser DisplayName using Ldapfilter

The LDAPFilter switch list the active directory objects that match the criteria specified in the LDAPFilter query.

To get aduser displayname using LDAPFilter, run the following script.

Get-ADUser -LDAPFilter "(SamAccountName=Toms)" -Properties * | Select-Object DisplayName, SamAccountName

In the above PowerShell script, the Get-AdUser cmdlet uses the LDAPFilter to specify the criteria where samaccountname = Toms and get aduser displayname from samaccountname.

The output of the above script retrieves the active directory user displayname using samaccountname and the Select-Object cmdlet shows displayname and samaccountname.

PS C:\> Get-ADUser -LDAPFilter "(SamAccountName=Toms)" -Properties * | Select-Object DisplayName, SamAccountName

DisplayName SamAccountName
----------- --------------
Tom Smith   toms

Cool Tip: How to get aduser samaccountname in PowerShell!

PowerShell Get-AdUser DisplayName Contains criteria

Use the Get-AdUser Filter parameter to check aduser displayname contains the specified string and retrieve the aduser all properties including the displayname and emailaddress

 Get-AdUser  -Filter {DisplayName -like "Tom*"} -Properties * | Select DisplayName, emailaddress

In the above PowerShell script, the Get-AdUser cmdlet uses the Filter parameter to specify the criteria where the displayname contains “Tom*” and retrieve the aduser all properties including the displayname and emailaddress.

The output of the above PowerShell script to get aduser with displayname contains the specified name is:

PS C:\> Get-AdUser  -Filter {DisplayName -like "Tom*"} -Properties * | Select DisplayName, emailaddress

DisplayName emailaddress
----------- --------------
Tom Smith   [email protected]


PS C:\>

Cool Tip: How to use dsquery to get user displayname!

PowerShell Get AdUser Manager DisplayName

To get aduser manager displayname in PowerShell, use the Get-AdUser cmdlet to retrieve the active directory user. It has a Manager attribute that stores the manager’s distinguishedname.

# Retrieve the manager of aduser
$aduser = Get-AdUser -Identity Garyw -Properties Manager

#Retrieve the manager user information like displayname
$manager = Get-AdUser $aduser.Manager -Properties DisplayName

# display the manager displayname
$manager.DisplayName

In the above PowerShell script, the Get-AdUser cmdlet uses the Identity parameter to specify the username to get aduser manager and stores the aduser object in the $aduser variable.

It uses the Get-AdUser cmdlet to specify the manager distinguishedname and retrieve the manager user information including the DisplayName and stores all the information in the $manager object.

The $manager.displayname display the aduser manager displayname on the console.

The output of the above PowerShell script to find aduser manager displayname is:

# Retrieve the manager of aduser
$aduser = Get-AdUser -Identity Garyw -Properties Manager

#Retrieve the manager user information like displayname
$manager = Get-AdUser $aduser.Manager -Properties DisplayName

# display the manager displayname
$manager.DisplayName

Aron Seth

Cool Tip: How to get ad group members displayname in PowerShell!

Conclusion

I hope the above article on how to get aduser displayname in PowerShell is helpful to you.

In the Active Directory, aduser displayname can be retrieved using samaccountname, distinguishedname, Filter or LDAPFitler query string.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.