Add a bunch of members to a Google Group

Add a bunch of members to a Google Group(s)
Let's say you'd like to add a bunch (more than 40 if not thousands) of email addresses to something like a Google Group in your Google Apps domain.  Or better yet, add a bunch of email addresses to a bunch of your Google Groups in your Google Apps domain.

Credit Where Credit is Due:
By the way, I didn't invent this.  So, before we get started, I'd like to make sure that credit is given to the guy who did.  Thanks +Jay Lee !! I owe you a few beers... or shots.  You saved me a ridiculous number of hours on my last Google Apps deployment.  Also, here's a link to where you can learn more.

Little Note:
I'm only going to discuss doing this from my Mac. While this can totally be done in Windows, that's up to you.

Step 1: GAM it up.
Download then install GAM. Oh yeah, and configure it for your domain... duh.

Step 2: Content
Create a Google spreadsheet and then download as a CSV. It should have 2 columns.
Column A = GroupID
Column B = Member email address

GroupMembers.csv
BluesDudes,jake.blues@atari.com
BluesDudes,elwood.blues@dogpile.com
CelebrityStuff,jake.blues@atari.com
CelebrityStuff,elwood.blues@dogpile.com
CelebrityStuff,cab.calloway@altaista.com

Step 3: Execute

sh addGroupMembers.sh

Here's the modified (simplified) script. I named it addGroupMembers.sh
There's more you can do for sure if you need to do some serious bulk loading. (i.e. using multiple superadmin accounts and oauth files)
#!/bin/bash

gam_command() {
  python gam.py update group "$group" add member "$member"
  }

IFS=,
x=1
while read group member; do
  group=${group//\"/}
  member=${member//\"/}
  gam_command $group $member &
  while (( $(jobs | wc -l) >= 20 )); do
    sleep 0.5
    jobs > /dev/null
    done
  x=$(($x+1))
  if [ $x -gt 20 ]
  then
    x=1
  fi
done < GroupMembers.csv

wait

Comments

Popular Posts