SOLVED: How to get a user's groups

124 views
Skip to first unread message

Thomas Burford

unread,
Jun 16, 2015, 3:07:15 PM6/16/15
to google-ap...@googlegroups.com
I've been racking my brain for a while now trying to figure out how to get just a user's groups that they're apart of. Seeing that there was no direct command (that I'm aware of), I decided to brute force the matter.

            $Groups = @()

            $TotalGroups = 0

            foreach ($line in (./gam info user $user)) {
                if($TotalGroups -gt 0) {
                    $Groups += $line.trim().split()[0]
                    $TotalGroups--
                }
                if($line.Contains("Groups:")) {
                    $TotalGroups = $line.split()[1].trim('(',')')
                    $TotalGroups = [int]$TotalGroups
                }
            }

This will end with $Groups containing a list of the groups the user is apart of. It's not the prettiest of solutions, but I'm rather new to Powershell. I've seen this question without answer atleast once on the forum, so I hope this helps!

Ed Crist

unread,
Jun 17, 2015, 8:58:21 AM6/17/15
to google-ap...@googlegroups.com
So here's a really simple way to get the output

gam print users groups todrive

This gives me 2 columns....username and groups

The 2nd column contains ALL groups that the user is a member of....each group is separated by a space

NOTE: I have 824 users and it runs a command on each on separately.....so it's NOT a fast report by any stretch, but it gave me what I wanted.

Jay Lee

unread,
Jun 17, 2015, 9:20:54 AM6/17/15
to google-ap...@googlegroups.com
You can also use:

gam print group-members

which will give you 1 row per group member. Note that external users will be included in this list.

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/4fe28b21-4b8e-43a3-a626-82e975d5c355%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Jay Lee

Reply all
Reply to author
Forward
0 new messages