Check OU contains Users or Computers Objects

Hello everyone,

I have an OU name. How Can check if specific OU contains Users or Computer Objects,

via LDAP query?



I should remove an organizational unit if it does not contains users or computer objects




Assuming this as not a scrip request.

You can use Get-ADObject targeting an OU and use Where-Object to filter by objectcategory.

PS: I’ve posted this without testing.