Update multiple groups membership from single csv in bulk?

352 views
Skip to first unread message

Josh Walker

unread,
Oct 3, 2018, 2:35:50 PM10/3/18
to GAM for G Suite
Hello, thank you for your time.

GAM is a godsend, I cannot believe I've gone so long without it. That said, I'm new, and I was hoping folks here could help clarify the best approach for a relatively simple task that I'm attempting to accomplish.

What I'd like to do is update all of our groups in one go from a CSV that was generated by GAM via:

gam print groups name members > groups.csv

I'd like to be able to make edits to the CSV, then turn around and update the memberships based on the new csv. I'm thinking I can just use: 

gam csv groups.csv gam update group ~Email update member ~Members

However, I'm a bit worried that it will be unable to update multiple members this way, as the documentation indicates the command is for a single user, and seems to imply that for a list of users, the 'file' argument should be used instead -- however, that would require creating a 'userlist' csv for each group, which I'd like to avoid. Any insight would be much appreciated.




619 S Bluff Street – Tower 2 – Ste 1B

St George, UT 84770

This communication, together with any attachments here to or links contained here in is property of Patriot Home Mortgage, for the sole use of the intended recipient's and may contain information that is confidential or legally protected. If you are not the intended recipient, you are hereby notified that any review, disclosure, copying, printing, dissemination, distribution or use of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by return e-mail message and delete the original and all copies of the communication, along with any attachments hereto or links here in, from your system. 

Patriot NMLS# 715386

www.nmlsconsumeraccess.org

Arizona: 0942696; California: 603K011; Colorado: 715386; Florida: MBR1182; Georgia: 36196; Idaho: MBL-7654; New Mexico: 715386; North Carolina: B-175118; North Dakota: MB103143; Oregon: ML-5139; Texas: 715386; Utah: 8015368 & 8015607; Virginia: MC-5644; Washington: CL-71536 & Wyoming: 3065



Ross Scroggs

unread,
Oct 4, 2018, 10:51:15 AM10/4/18
to google-ap...@googlegroups.com
Josh,

Collect the group membership info this way:
gam print groups name members delimiter " " > groups.csv
Without the delimiter " ", the members of each group are separated by newlines which makes the file very hard to process.

You update command should look like this:
gam csv groups.csv gam update group ~Email sync member ~Members

Unfortunately, this command won't work in standard Gam, it does work in my Advanced GAM (https://github.com/taers232c/GAMADV-XTD)
Here is a simple script that will do what ypu want with standard Gam.

Ross

#!/bin/bash                                                                                                                                                                                                                                                                                                          
#                                                                                                                                                                                                                                                                                                                    
# Sync group membership from CSV file with standard GAM                                                                                                                                                                                                                                                              
# This script assumes that the CSV file was generated by this gam command                                                                                                                                                                                                                                            
# gam print groups name members delimiter " " > groups.csv                                                                                                                                                                                                                                                           
# Usage: ./SyncGroups.sh groups.csv                                                                                                                                                                                                                                                                                  
#                                                                                                                                                                                                                                                                                                                    
GAM="/Put/Path/To/Gam/Here"
CSVFILE="$1"
{ while IFS=',' read Email Name MembersCount Members
    do
    $GAM update group $Email sync member users "$Members"
    done ; } < $CSVFILE


--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" 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 https://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/ae75b66a-840c-4150-9ea0-68831d3489fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages