You can use the dsquery utility (available on DC's with W2k3 or above) with the Find command to get useful information. For example, to count the total number of users in your domain:
dsquery * -filter "(&(objectCategory=person)(objectClass=user))" -limit 0 | find /c /i "cn="
To count the number of enabled users:
dsquery * -filter "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))" -limit 0 | find /c /i "cn="
To count the number of users that have changed their password since January 1, 2011:
dsquery * -filter "(&(objectCategory=person)(objectClass=user)(pwdLastSet>=129383316000000000))" -limit 0 | find /c /i "cn="
To count the number of users that have logged on since January 1, 2011:
dsquery * -filter "(&(objectCategory=person)(objectClass=user)(lastLogonTimeStamp>=129383316000000000))" -limit 0 | find /c /i "cn="
The last works if your domain is at Windows Server 2003 functional level or above. I used the following VBScript program to convert the date "January 1, 2011" into the large 64-bit integer that can be compared to the pwdLastSet and lastLogonTimeStamp attributes:
http://www.rlmueller.net/Programs/DateToInteger8.txtI think you can also do this conversion in PowerShell, but I haven't figured out how yet. Finally, "dsquery user" has the -stalepwd and -inactive switches that you can use. Check the help at a command prompt of a DC. To count the number of users with a stale
password at least 75 days old:
dsquery user -stalepwd 75 | find /c /i "cn="
Similarily, to count users that have been inactive for the last 10 weeks:
dsquery user -inactive 10 | find /c /i "cn="
This last example uses the lastLogonTimeStamp attribute of the users, so the domain must be at Windows Server 2003 functional level or better.
Richard Mueller - MVP Directory Services
Need to support users over the internet?
click here try our remote control online beta