I think this is the sort of thing you're looking for: removing-leaf-objects-from-active-directory
LDAP query leaf object

Looking for a way to use Powershell to query leaf objects of an AD account. In particular, I am trying to query the ExchangeActiveSync leaf objects under a user account in AD. I am able to query the AD account in Powershell itself, but not sure about a way to view the leaf objects of that account.
Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
3 additional answers
Sort by: Most helpful
-
Rich Matheisen 47,901 Reputation points
2020-11-12T19:33:33.057+00:00 Is there a reason you aren't using the Exchange cmdlets to do this?
I'm pretty sure the cmdlet Get-CASMailbox would return what you need.
-
R3K3 41 Reputation points
2020-11-12T20:25:50.593+00:00 The data for ActiveSync connections is stored in the leaf objects, every so often I have users that build up a large number of these due to ActiveSync code and they need to be erased. Using Exchange is too slow to run this query against thousands of users, my environment is fortune 20 level. When I run the following command I can see ActiveSync connections in Exchange..
Get-ActiveSyncDeviceStatistics -Mailbox $user | sort LastSuccessSync -Descending | ft LastSuccessSync,DeviceType,DeviceModel,DeviceOS,Guid,Status
I am trying to delete the ones in the above list that have a LastSuccessSync date of older than X days, say 30 in this example. I would much rather have this run at the LDAP level than on my Exchange servers.
-
R3K3 41 Reputation points
2020-11-13T20:16:51.253+00:00 Nice. Thanks, that gave me the ideas I needed.