The problem is creating the DirectorySearcher object. To set the search root correctly, DirectorySearcher must be constructed using a DirectoryEntry object (ADSI type accelerator), while you are using a string. When a string is used, the string is used as an LDAP filter, and the search root is null, forcing the crawler to use the root of the current domain. That's why it looks like you are not looking for the OU that you want.
I think you will get the results you are looking for if you do something like the following:
$searchroot = [adsi]"LDAP://OU=USERS BY SITE,DC=Domain,DC=local" $seek = New-Object System.DirectoryServices.DirectorySearcher($searchroot) $seek.Filter = "(&(name=$OUToSeek)(objectCategory=organizationalunit))" ... etc ...
Note that the DirectoryEntry constructor is created first, which is then used to create the DirectorySearcher.
source share