Author Posts

September 21, 2014 at 1:49 pm

I am having a WTF moment here.

Can someone please explain to me why these two produce different count results.

Thank you very much.

[u][b]Using Get-ADObject
[/b][/u]

The following code for my environment produces a value of 2603:

$GetADObject = Get-ADObject -Filter 'ObjectCategory -eq "User"'

$ADObjectCount = $GetADObject.Count

$ADObjectCount

[u][b]Using Get-ADUser[/b][/u]

The following code for my environment produces a value of 2562

$GetADUser = Get-ADUser -Filter *

$GetADUser.Count

September 21, 2014 at 2:11 pm

The different number is because the user category contains also computer accounts, not only user accounts. In order to obtain the result you want you have to use ObjectCategory -eq "Person".

September 21, 2014 at 3:11 pm

AAHHHHHHH geez, I completely forgot about the "Person" identifier.

Sweet!

Thanks man

September 21, 2014 at 3:19 pm

Nope, it's still off by the same values. Anything else it could be?

Should I just go with Get-ADUser instead of Get-ADObject?

Thanks again

September 21, 2014 at 5:53 pm

To retrieve only user accounts, you need to filter on both objectCategory = 'Person' and objectClass = 'User'. There are probably other combinations which get a similar result, but this is how I learned it, back in the Windows 2000 Active Directory days:

$users = Get-ADObject -Filter 'objectCategory -eq "person" -and objectClass -eq "user"'

September 22, 2014 at 7:19 am

Sounds good. Thanks again, Dave