Skip to main content

Bulk creating Google Groups and Calendars in Google Apps and populating them with users for free

Suppose you want to make loads of groups and calendars and populate them with users and don't want to spend any money on any tools to do it. Well you can use GAM and a couple of scripts to do this. In a school you might want a Google Group and Calendar for each teaching group. You can achieve this using paid for tools such as Hapara's TeacherDashboard and tools that sync your MIS to AD and then to Google Apps - but these cost money and in the second case assume you actually have active directory.
So this is how to do it without any of those tools and zero cost.

Creating Groups

You will need a csv file with a list of group names first - classes names perhaps. Save the csv file to your GAM directory. Run the following command:

gam csv groups.csv gam create group ~groups

groups.csv = your csv file, the 'groups' in ~groups = the name of the column of groups in the csv file.

Populate with group owners

You might want teachers to be group owners. So to add them to the groups you will need a csv file with the email address of the teacher next to the classes they teach - so two columns. Each teacher could have multiple rows if they teach many classes. Run the following command:

gam csv teachers.csv gam update group ~group add owner user ~teacher

Again the ~group/teacher refer to the column heading on the csv file.

Populate with members

Students you might want to add as members. So you need a csv file with the email address of all the students next to the classes they take (the group email address - groupname@domainname). Run the following command:

gam csv students.csv gam update group ~group add member user ~students

Thats it for groups. Note, for the students where there are likely to be 1000's of lines, it can take a while to run!

Create Calendars

There is not a GAM command to create regular calendars, so you need to use a script. To make calendars, add the following script to a Google Sheet:
Create all those calendars:
function createcalendars() {
 var sheet = SpreadsheetApp.getActiveSheet();
 var data = sheet.getDataRange().getValues();
 for (var i = 0; i < data.length; i++) {
   Logger.log(data[i][0]);
 }
 for (var  i = 0; i < data.length; i++) {
   var calendar = CalendarApp.createCalendar(data[i][0]);
   Logger.log('Created the calendar "%s", with the ID "%s".',
    calendar.getName(), calendar.getId());
 }
}

This will read a list of calendar names from the Google Sheet and create them (good idea to do this on one central calendar owner user!) . So use the same name as you used for the group. You can use GAM to populate the calendars, but you first need the calendar email address. You can add this script to another sheet to list all the calendars.
function listCals() {
var calendars = CalendarApp.getAllOwnedCalendars();
data = []
for (var i = 0; i < calendars.length; i++) {
data.push([ calendars[i].getId(), calendars[i].getName()])
}
var destinationRange = SpreadsheetApp.getActiveSheet().getRange(1, 1, data.length, data[0].length);
destinationRange.setValues(data);
};

function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "List Owned Calendars",
functionName : "listCals"
},];
sheet.addMenu("Calendar", entries);
}

Populate Calendars 

You will need a csv file with a list of your calendar owners (teachers) and the calendars they own (you will need to match calendar email address to the group). Run the following command:

gam csv teachcal.csv gam calendar ~calendar add editor ~teacher

for students -

gam csv studentcal.csv gam calendar ~calendar add read ~student

Where ~ goes before the name of the heading of the appropriate column in the CSV file.

Automating the process

You could put all of these GAM commands into a windows batch file (*.bat) and run it as a scheduled task overnight once a week to update groups as long as you can update the csv files. 

Comments

Popular posts from this blog

Delete a specific email using GAM

If a user send an inappropriate email to a loads of people or get stung by some sort of email exploit you can quickly delete the email from all of the recipients using a GAM command. Step 1 - get the email header Go into Google Vault and search for the offending user or someone known to have got the message. Click show details and grab the email ID. This will be a long string of characters followed by @mail.gmail.com Step 2 - find out who has the email Go into Google Vault and find the original message sent by the offending user. Look at the details to see who got it. Copy the list and dump it into a spreadsheet. Clean up to just a list of emails with a column header 'mail'. Save as a csv file. Step 3 - delete messages with GAM Put your CSV file in your GAM folder - this e.g. assumes its called mail.csv Run: gam csv mail.csv gam user ~mail delete messages query rfc822msgid: MESSAGEIDHERE doit The alternative nuke option is: gam all users delete messages query rf...

Adding subdomains to G Suite

This is how I add subdomains (so basically new schools) to out G suite setup. I've got these steps documented on a scruffy set of notes that I've now got in Keep - so time to document them - for myself as much as anyone else! Steps in order (roughly) Add the new domain Verify the new domain Add MX records to hosting Add SPF record for Google to hosting Turn on email authentication Add DMARC record to hosting Setup custom Directory and restrict students OU to this. Create an admin quarantine for the domain. Configure SPAM setting for the domain. Turn on and off services as appropriate. Map a blank Google Site to the naked domain - if required. Setup some basic groups - allstaff, allusers (for directory) and students with appropriate permissions. Deploy custom wallpapers. So the steps in a bit of detail: Add the new domain & Verify ownership Click on Domains in the admin console: Add/remove domains followed by "add a domain" At this...

My favorite GAM commands - well a few of them at least!

Where would be without GAM? Paying for expensive syncing tools or doing tedious manual tasks in the admin console. GAM can automate most things you might want to do in G Suite. So these are a few of my favourite commands - one I use either as part of a batch file - or just standalone. There are loads more - but these are ones that are used daily. Classroom Create a spreadsheet of all your domains classes -  gam print courses todrive Create a spreadsheet of a teacher's classes:  gam print courses teacher fred@mydomain.com todrive Bulk create classes: gam csv classes.csv gam create course alias ~alias name ~alias section ~subject teacher ~teacher status ACTIVE where classes.csv is a list of classes you want to make. Add teachers: gam csv teachers.csv gam course ~alias add teacher ~teacher Add students: gam csv students.csv gam course ~alias add teacher ~student Sync Students (in this example to a group - but could be an ou/csv file) gam csv grou...