header image

Multiple LDAP filters

Posted by: | June 27, 2015 Comments Off on Multiple LDAP filters |

Continuing our look at LDAP filters – remember the data set in use:

£> Get-ADUser -SearchBase ‘OU=Testing,DC=Manticore,DC=org’  -Properties * -Filter * | select Name

Name
—-
Dave Green
Dave Brown
Dave White
Jo Daven
Fred Green
Dale Greensmith
Dave Greenly

 

Individual filters work like this

£> Get-ADUser -SearchBase ‘OU=Testing,DC=Manticore,DC=org’  -Properties * -LDAPFilter ‘(givenName=Fred)’ | select Name

Name
—-
Fred Green

£> Get-ADUser -SearchBase ‘OU=Testing,DC=Manticore,DC=org’  -Properties * -LDAPFilter ‘(sn=Green)’ | select Name

Name
—-
Dave Green
Fred Green

 

You have two options for joining filters:

AND – uses & symbol

OR – uses | symbol

 

£> Get-ADUser -SearchBase ‘OU=Testing,DC=Manticore,DC=org’  -Properties * -LDAPFilter ‘(&(givenName=Fred)(sn=Green))’ |
select Name

Name
—-
Fred Green

£> Get-ADUser -SearchBase ‘OU=Testing,DC=Manticore,DC=org’  -Properties * -LDAPFilter ‘(|(givenName=Fred)(sn=Green))’ |
select Name

Name
—-
Dave Green
Fred Green

under: PowerShell and Active Directory

Comments are closed.

Categories