I needed to test something today, therefore I required a quick way to query a particular OU in my test environment. I find it easier to use PowerShell for such tasks.

# Set the path to the OU you want to search
$ouPath = "OU=Computers,DC=example,DC=com"

# Perform the search
$searcher = [adsisearcher]"(objectCategory=computer)"
$searcher.SearchRoot = "LDAP://$ouPath"
$searchResults = $searcher.FindAll()

# Output the results
foreach ($result in $searchResults) {
    Write-Host $result.Properties["name"]
Shows execution and results from proposed PowerShell script.

In this script, replace “OU=Computers,DC=example,DC=com” with the path to the OU you want to search. The script performs an LDAP search for all objects in the OU that have a category of “computer”. It then outputs the name of each computer found in the search results.

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.