I would like to get output for multiple “ObjectCategory” values using the Get-ADObject cmdlet and it doesn’t work if I create an array as in the following example:
The -Filter parameter is processed at the DC - and the DC isn’t capable of handling variables. Further, the DC can’t process an array. You’d need to run this as multiple queries, or construct a much more complex LDAP query involving OR clauses.
You should be able to construct a filter with multiple checks on object categories joined by -or . (You can do this in the LDAP filter syntax, or with -Filter; whatever your preference.) If you want to write a function that accepts an array, this filter string can be constructed dynamically: