LDAP Query

Is there a way to query OU's that Match a certain name, with the computer objects in it.

Example:   I want to query all call computers,  that are in an OU,  that have the Name "Servers"

thank you for your help

February 25th, 2015 3:07pm

Here you go:

$allcomputers = Get-ADComputer -Filter *
foreach ($computer in $allcomputers)
{
	if ($computer.DistinguishedName -like "*Server*")
	{
		$computer.name
	}
}

Free Windows Admin Tool Kit Click here and download it now
February 25th, 2015 4:43pm

Thank you for your reply.   I was looking for something to query Active Directory.   I have an application that I can do custom queries.    this query gives me all the OU's that have the name "Server" ,   however, I need the computer in those OU's.   (&(objectclass=organizationalunit)(name=Server))

Thank you.

February 25th, 2015 9:05pm

Is there a way to query OU's that Match a certain name, with the computer objects in it.

Example:   I want to query all call computers,  that are in an OU,  that have the Name "Servers"

thank you for your help

Run this via PowerShell in your Domain Controller. PowerShell is installed automatically if you have 2008 R2. 

Import-Module activedirectory
Get-ADComputer -Filter {name -like "*server*"} -Searchbase "OU=Computers,DC=Contoso,DC=com" | FT		
Free Windows Admin Tool Kit Click here and download it now
February 25th, 2015 11:04pm

For LDAP filters, only equality operator is allowed for the DistinguishedName. Richard already described that here: http://social.technet.microsoft.com/wiki/contents/articles/5392.active-directory-ldap-syntax-filters.aspx

If only LDAP filters are allowed for searching then you won't be allowed to search based on the DN. However, you might think about the following:

  • Create a custom attribute like COMPANYCustom1
  • Create Powershell scripts that will set a special flag in COMPANYCustom1 dependent of the computer DN
  • Use COMPANYCustom1 for LDAP filtering by the application
February 26th, 2015 4:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics