Today a colleague and I had a competition to write a script to count the number of users in an AD security group. My colleague made a PowerShell script to count the users in the group, while I worked on a command line script using dsquery. I finished first, but only because I found a copy of a script I made before. Here’s the PowerShell script:
(Get-ADGroupMember -identity “domain admins”).count
The PowerShell script was much better than mine, because my script outputted the users in a group into a CSV, which I then opened in Microsoft Excel and counted the number of rows.