count members in security group in o365

Is there a way to count the number of members that are part of security groups that are all part of a big security group.

Thank you.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amit KumarCommented:
user this one after connecting Exchange online powershell

(get-distributiongroupmember -identity GroupName).count
To amit'.s point, over the past four months there are several questions/answers on this topic within EE dealing with using,powershell to run nested queries after using powershell to connect to office365 ps interafce.
miki0Author Commented:
It only gives me a number of sub-groups that are part of this group. :/
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

You have to nest .

Please provide as much detail as what the end result you want.

Do you want group
         Members of of group
               Members of


Or do you want to count members direct and based on nested groups.
miki0Author Commented:
Just looking for a total number of members that are part of this big group that doesn't have direct members  as users in, but rather sub-groups that have members. Does this make sense now?
One way is to get the aggregate, or have a report that
Top group
        Direct member
                 Sub group members
                  Sub subgroup
                          Sub subgroup members

You possibly could maintain a central count of users, you enviably might get surprised how many members. And would need to ...

The iterative where you provide the root group, when a group is found, it will call the same function......

Let me work this through...
miki0Author Commented:
I have 174 or so universal-security "email enabled" groups, under one OU in AD called Security Groups. I am syncing them to O365 and have created one Distribution group in the cloud - O365 called "GroupOfTheDay" which these groups are part of, and every day different groups are part of this O365 distribution group. Those 174 universal groups in my AD are auto populated by our FIM. Things are changing from day to day so to have different groups as members is so annoying and gives me headaches. This script should have to be immune to those changes and always ready to give me the right and correct "Total" number of members-users that are part of this group for the day.
This is just a short story of otherwise same question I posted initially for this topic.
Thank you for the help in advance.
Since you seem to need to run thi periodically defining your own function will do the repetitive

Have not worked it out but thought to include it
Th combination of

To name the function
Get-allmembers  groupname  optional (counter)
One is a counter of users
For each group in get-distributiongroupmembers -identity groupname
Call the function with the new groupname and .....

The reference defines the function in your o365 .......

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
miki0Author Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.