You can get a list of adusers from the active directory using the Filter or LDAPFilter parameter. Use the Get-AdUser Filter with multiple attributes to search and retrieve one or more users which satisfy the filter condition.
Filter or LDAPFilter parameter is used to filter active directory objects. You can use multiple attributes to specify the query string.
In this example, we will discuss how to get aduser filter with multiple attributes using the Get-AdUser cmdlet in PowerShell.
Using Get-AdUser Filter with Multiple Attributes
Use the Get-AdUser cmdlet in PowerShell to get one or more aduser filters with multiple attributes.
To get aduser from the Sales department having an office location in Houston, run the following command.
Get-ADUser -Filter {Department -eq 'SALES' -ANd PhysicalDeliveryOfficeName -eq 'Houston'}
In the above PowerShell script, the Get-AdUser uses the Filter parameter to specify a query string having multiple attributes.
In the script, we have specified multiple properties like Department and PhysicalDeliveryOfficeName to retrieve one or more adusers.
The output of the above PowerShell script to get aduser filter with multiple properties is:
Using Get-AdUser LDAPFilter with Multiple Properties
You can use LDAPFilter with multiple properties to retrieve one or more adusers.
To get adusers from the Sales department having an office in Houston location, use the LDAPFilter to specify the query string for the Department and PhysicalDeliveryOffice attributes.
Get-ADUser -LDAPFilter "(&(Department=SALES)(PhysicalDeliveryOfficeName=Houston))"
In the above PowerShell script, the Get-AdUser uses LDAPFilter with multiple properties like Department and Office to get one or more active directory users.
The output of the above script to get aduser LDAPFilter with multiple properties is:
PS C:\> Get-ADUser -LDAPFilter "(&(Department=SALES)(PhysicalDeliveryOfficeName=Houston))"
DistinguishedName : CN=Tom Smith,OU=SALES,DC=SHELLPRO,DC=LOCAL
Enabled : True
GivenName : Tom
Name : Tom Smith
ObjectClass : user
ObjectGUID : 1f3a2572-2621-4e47-9bdf-81d1f8172f69
SamAccountName : toms
SID : S-1-5-21-1326752099-4012446882-462961959-1103
Surname : Smith
UserPrincipalName : [email protected]
Conclusion
I hope the above article to get aduser filter with multiple attributes using the Filter or LDAPFilter parameter is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.