Wednesday, May 16, 2018

Quick script to count number of groups a user has in Active Directory.

I had the issue of users with too many groups to login so I needed a fast way to get a group count.

groups.bat 
dsquery user -samid %1| dsget user -memberof | wc

C:\>groups testuserC:\>dsquery user -samid testuser  | dsget user -memberof   | wc      215       635     16530C:\>

The number of groups is 215.

You need the WC unix utility. I always keep WC and GREP on hand.