I have a question on how to exclude a specific OU when running this PS statement. This gives me all the servers in the Domain. I like to excluded the OU called
OU=RETIRED,OU=SERVER,DC=ABCCORP,dc-com
Tried some filtering but no luck.
$ObjFilter = "(operatingsystem=*SERVER*)"
$objSearch = New-Object System.DirectoryServices.DirectorySearcher
$objSearch.PageSize = 15000
$objSearch.Filter = $ObjFilter
$objSearch.SearchRoot = "LDAP://dc=ABCCORP,dc=com"
$AllObj = $objSearch.FindAll() | Select-Object @{n='Name';e={$_.properties['name']}}
You can pipe the search result to
Where-Object
and filter based on the LDAP Path.change:
to: