The Problem
It's not uncommon for schools and corporations to manage thousands of Chrome Devices, specifically Chromebooks. Moving these Chrome devices across organizational units (OU) is a technique for deploying different enterprise policies. For school environments, Chrome devices often follow the change of students' OUs as they grow up. That said, Google Admin Console can allow you move limited Chrome devices to an organizational unit at a time. If you need to migrate over thousands of devices, it's very inefficient.
The Solution
The following open source Google Apps Script can help you automate the process of moving all Chrome devices from one OU to another.
Instructions
- Open https://script.google.com.
- Click New project.
- Name the script project in the title
- Copy and paste the following script to the script editor, overwriting existing
function myFunction() {}
code - Modify the
sourceOU
anddestinationOU
variables to matching your own case. These are the OU paths in the format of/OU/SubOU/SubSubOU
. The root domain is represented by/
. - Click Services in the left navigation panel
- Select Admin SDK API
- Click Add
- Click in the toolbar
- Click Run
- It will ask for your permissions in the first run
- After you grant the permission, the script shall move all your chrome devices from the
sourceOU
to thedestinationOU
.
Source code
/** * Move all Chromebooks from one OU to another OU * * Usage: * Replace the `sourceOU` and `destinationOU` * with your OU setup, in a format of /OU/SubOU/SubSubOU. * * © 2021 xFanatical, Inc. * @license MIT * @version 1.0.0 */ const sourceOU = '/sourceOU' const destinationOU = '/destinationOU' function moveChromebooks() { let pageToken let page do { page = AdminDirectory.Chromeosdevices.list('my_customer', { maxResults: 100, pageToken: pageToken, orgUnitPath: sourceOU, }) let chromeosdevices = page.chromeosdevices if (chromeosdevices) { for (let i = 0; i < chromeosdevices.length; i++) { const chromeosdevice = chromeosdevices[i] Logger.log('Moving chromebook ID: %s; SN: %s', chromeosdevice.deviceId, chromeosdevice.serialNumber) AdminDirectory.Chromeosdevices.update({ orgUnitPath: destinationOU, }, 'my_customer', chromeosdevice.deviceId) } } else { Logger.log('No chromebooks found.') } pageToken = page.nextPageToken } while (pageToken) }
If you're interested in extending functions or automating your tasks as much as possible on Google Workspace, please check out our code-free workflow automation software Foresight. We also provide custom apps script development services to increase your productivity. Please don't hesitate to contact us. It's our passion and expertise to assist you on Google Workspace.