Bulk Adding Calendars to a Google Account for Migration

In my last Google migration post, I talked about creating a MigrationWiz project with the correct resource and folder mappings to support a large-scale project.

One of the requirements is that the resource calendar *must* be opened/mounted on the calendar of the admin user that you'll be using on the Google side.  Again, a simple task if it's adding 2 or 3 calendars.  But hundreds?

Fortunately, someone smarter than me built the Google Apps Manager command-line tool, which will let us do exactly that.

Here are the steps to getting off to the races:

  1. Download GAM and extract to a folder, such as C:\GAM.
  2. Create the authorizations files (client_secrets.json and oauth2service.json) by following these instructions (hint: you'll need to register another application in Google Apps).  The Cliff Notes version:
    1. Log into your GoogleApps domain (https://www.google.com/a).

    2. Click Security.

    3. Click API Reference.

    4. Click the checkbox to enable API access (if not already enabled) and click Save.

    5. In a new browser tab, go to https://console.developers.google.com/flows/enableapi?apiid=admin,appsactivity,calendar,classroom,drive,gmail,groupssettings,licensing,plus,contacts to create a new Google API Project.

    6. If you've never created an API project before, you'll get something that looks like this.  Agree and continue to go to the next step.
      1

    7. Once it's done, you should be notified that the APIs are enabled and you can continue. Click Go to credentials to continue.
      2

    8. Click cancel.

    9. On the left hand side of the screen, select the Credentials link, and then select the OAuth Consent screen link in the middle of the page.
      3

    10. On the OAuth Consent screen, enter a value in "Product name shown to users" (you can use the same name as your project if you want) and then click Save.
      4

    11. Click the Create Credentials button, and select OAuth Client ID from the drop-down.
      5

    12. Select the Other radio button, enter a name, and then click the Create button.
      6

    13. Download the Client OAuth Key using the download icon at the right of the page and save it to the same folder as the GAM binary, renaming as client_secrets.json.
      7

    14. Click the Credentials drop down, select Service Account Key, and then select New Service Account.
      8

    15. Enter a service account name and account ID, and ensure the JSON radio button is selected.  Click Create.
      9

    16. If you get a dialog box complaining about no role, in your most nihilistic voice announce that no one has any roles, and then click Create without role.
      10

    17. You'll immediately receive a prompt to download a file.  Save it to the GAM folder, renaming it to oauth2service.json.

    18. On the credentials page, in the Service account keys section, click the Manage service accounts link.

    19. Click the service account, then select the ellipsis icon at the end of the row, and select Edit.

    20. Select the checkbox Enable Google Apps Domain-wide Delegation and click Save.
      11

    21. Next to the Google APIs logo at the top of the screen, click the hamburger menu/card stack, and select API manager, and then select Credentials.

    22. Select the Client ID for the type Other and copy it (Control-C) to your clipboard.

    23. In your browser, select the Admin Console tab (which should still be on API Reference), then click the Show More link at the bottom of the screen.  Click Advanced Settings, then click Manage API Client Access. 12

    24. Paste the Client Id in the Client Name field.

    25. Copy/paste the following data into the One or More API Scopes text box:

       https://mail.google.com/,https://sites.google.com/feeds,https://www.googleapis.com/auth/activity,https://www.googleapis.com/auth/admin.datatransfer,https://www.googleapis.com/auth/admin.directory.customer,https://www.googleapis.com/auth/admin.directory.domain,https://www.googleapis.com/auth/admin.directory.resource.calendar,https://www.googleapis.com/auth/calendar,https://www.googleapis.com/auth/classroom.courses,https://www.googleapis.com/auth/classroom.guardianlinks.students,https://www.googleapis.com/auth/classroom.profile.emails,https://www.googleapis.com/auth/classroom.profile.photos,https://www.googleapis.com/auth/classroom.rosters,https://www.googleapis.com/auth/cloudprint,https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/plus.login,https://www.googleapis.com/auth/plus.me,https://www.googleapis.com/auth/siteverification,https://www.google.com/m8/feeds/contacts
      
    26. Click Authorize.

    27. Go back to the Credentials tab, select the Client ID for the Service Account client, and copy it to the clipboard.

    28. Go back to the Admin Console Manage API client access window in the browser, and then paste the client ID into the Client name field.

    29. Copy and paste the following data into the One or More API Scopes text box:

       https://mail.google.com/,https://sites.google.com/feeds,https://www.google.com/m8/feeds/contacts,https://www.googleapis.com/auth/activity,https://www.googleapis.com/auth/calendar,https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/gmail.settings.basic,https://www.googleapis.com/auth/gmail.settings.sharing,https://www.googleapis.com/auth/plus.login,https://www.googleapis.com/auth/plus.me,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile
      
    30. Click Authorize.

    31. Launch a command prompt and change to the directory where the GAM binary and Google Authorization files have been copied.

    32. Type gam oauth create and press Enter.
      13

    33. At the command window, select c to continue.
      14

    34. A browser window will pop up, and you should be asked to authorize the project you've created.  Click Allow at the bottom of the screen to authorize access.
      15

    35. After authorizing, you should receive a message indicating that the authorization was complete.
      16

    36. You can then run the command to update a target user's calendar:

       gam user adminmailbox@domain.com add calendar resource.calendar@resources.google.com selected true
      
    37. If you get a message similar to the following, you will need to enable Calendar access in the Google Admin portal.
      ERROR: 403: Access Not Configured. Calendar API has not been used in project 578301497795 before or it is disabled. Enable it by visiting https://console.developers.google.com
      /apis/api/calendar/overview?project=<project-id> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. - accessNotConfigured
      18

  3. Then, bundle it all up in a script.  You can use the GAM CSV import method, but since I'm a PowerShell kind of a guy, I figured I'd just take the CSV from my last post and re-use it here.
    1. Launch PowerShell window and change to the C:\GAM directory.

        $Resources = Import-Csv GoogleResources.csv
       $GoogleAdminEmailAddress = "admin@domain.com"
       Foreach ($obj in $Resources)
       {
       Write-Host "Processing $($obj.GoogleAppsResourceEmail)..."
       .\gam user $GoogleAdminEmailAddress add calendar $obj.GoogleAppsResourceEmail selected true
       }
      
    2. View the updated calendar in Google.

Happy migrating!