Powershell: count members of a AD group

Question:

RECIEVED AN EXAMPLE I COULD USE AND CORRECTED CODE

My current question is how to count amount of members in a group versus printing out all members of a group (which includes their ID name or PC name). The commented out code prints each member. I just want to count them.

I’ve tried $members.count, $member.count and $string.count in my foreach loop but nothing prints out. Please help

I made an edit based on Alex McKenzie’s comment. The initial example you gave me made issues.
I tried adding some edits to it but I get a error: Cannot validate argument on parameter ‘Identity’. The argument is null or empty. Supply an argument that is not null or empty and then try
the command again.

Below is my finished code. I just made separate .txt files for each things I needed and will just separately import them into excel. QUESTION FIXED

I add a counter in original script if I want it to get count as well

Answer:

The Get-ADGroupMember cmdlet would solve this in a much more efficient way than you’re tying.

As an example:

EDIT:

In order to clarify things, and to make your script simpler. Here’s a generic script that will work for your environment that outputs the user count for each group matching your filters.

Source:

Powershell: count members of a AD group by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply