Powershell

Get-AdUser: Finding Active Directory Users With PowerShell

The “Get-AdUser” cmdlet is used to retrieve one or more Active Directory users in PowerShell. Moreover, it gets the user object specified by the user. It can also perform a search to retrieve a number of user objects. The “-Identity” parameter is used with the stated cmdlet to identify the user by its distinguished name or by its security identifier (SAM).

In this post, the “Get-ADUser ” cmdlet will be discussed.

Get-ADUser: Finding Active Directory Users With PowerShell

As described above, the stated cmdlet is responsible for getting the list of users based on the parameters provided.

Let’s have a look at the examples related to the stated cmdlet.

Example 1: Use the “Get-ADUser” Cmdlet to Get All the Users in the Container

To get the list of all the users in the specified container, run the provided cmdlet:

Get-ADUser -Filter * -SearchBase "OU=Finance,OU=UserAccounts,DC=JOHNDOE,DC=COM"

 

According to the above code:

  • First, write the “Get-ADUser” cmdlet, followed by the “-Filter” parameter and the “*” wildcard.
  • After that, create another parameter “-SearchBase” parameter and assign the stated value.

Example 2: Use the “Get-ADUser” Cmdlet to Retrieve a List of Filtered Users

The below-given demonstration can be used to get the filtered list of users:

Get-ADUser -Filter 'Name -like "*SvcAccount"' | Format-Table Name,SamAccountName -A

 

In the above-stated code:

  • First, specify the “Get-ADUser” cmdlet along with the “-Filter” parameter having the stated filter assigned to it.
  • In the created filter, first, add the “Name” followed by the “-like” parameter and assign the string value “*SvcAccount”.
  • After that, add the “|” pipeline along with the “Format-Table” cmdlet having the values “Name” and “SamAccountName”.
  • Lastly, add the “-A” parameter.

Example 3: Use the “Get-ADUser” Cmdlet to Get the Properties of a Specified User

To list down the properties of a specified user execute the given command:

Get-ADUser -Identity JamesBen -Properties *

 

In the above-given code snippet:

  • First, specify the “Get-ADUser” cmdlet along with the “-Identity” parameter having the value “JamesBen” assigned to it.
  • Lastly, specify the “-Properties” parameter and add the “*” wildcard.

Example 4: Use the “Get-ADUser” Cmdlet to Get a Specified User

To retrieve the user specified in the code, run the provided cmdlet:

Get-ADUser -Filter "Name -eq 'JohnDoe'" -SearchBase "DC=AppNC" -Properties "mail" -Server lds.Jamesben.com:50000

 

In the above-given code:

  • First, specify the “Get-ADUser” cmdlet, along with the “-Filter” cmdlet, and assign the stated filter.
  • After that, add the “-SearchBase”, “-Properties”, and the “-Server” parameters. Then, assign the stated values to them.

Example 5: Use the “Get-ADUser” Cmdlet to Get the List of All enabled Users With the Help of the “-LDAPFilter” Parameter

Get the list of all enabled users with the help of the “-LDAPFilter” parameter, as follows:

Get-ADUser -LDAPFilter '(!userAccountControl:1.2.840.113556.1.4.803:=2)'

 

According to the above code, first, specify the “Get-ADUser” cmdlet followed by the “-LDAPFilter” parameter and assign the stated value.

That’s all about the “Get-ADUser” cmdlet for finding the active dictionary users with PowerShell.

Conclusion

The cmdlet “Get-ADUser” is used to retrieve the chosen user object or conduct a search to obtain a list of several user objects. Moreover, a customized list of users can be retrieved with the aid of several parameters. This post has elaborated on the “Get-ADUser” cmdlet in detail.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.