Skip to main content
  1. Posts/

Deprovision Chromebooks with GAM by Serial Number

·214 words·2 mins

Have you ever needed to quickly and easily deprovision a bunch of Chromebooks. If you have a list of their serial numbers it’s a snap with GAM. You can copy and paste the code below into a local file. I chose deprovision_by_sn.sh. Be sure to update the PATH to GAM and make the file executable using the chmod u+x option.

 1#!/bin/bash
 2
 3# Assuming the first line of the CSV is the header and serial numbers start from the second line.
 4
 5INPUT="deprovision.csv"
 6
 7OLDIFS=$IFS
 8IFS=','
 9[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
10while read -r SerialNumber
11do
12  echo "Processing $SerialNumber..."
13  # Retrieve the device ID using the serial number
14  deviceID=$(“PATH TO GAM”/gam print cros query "id:$SerialNumber" | sed -n '2p')
15  if [ ! -z "$deviceID" ]; then
16    # Deprovision the device
17    “PATH TO GAM”/gam update cros "$deviceID" action deprovision_retiring_device acknowledge_device_touch_requirement
18  else
19    echo "No device found for Serial Number: $SerialNumber"
20  fi
21done < <(tail -n +2 $INPUT) # Skip the header
22IFS=$OLDIFS

The script looks for the file deprovision.csv in the same directory as the script. Be sure the file begins with the header SerialNumber. Then each line can contain a serial number you wish to deprovision.

Corey Grim
Author
Corey Grim