-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprovisionDevice.gs
30 lines (30 loc) · 1.35 KB
/
deprovisionDevice.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function deprovisionCB(sernum) {
var serno = sernum;
// Since we provided serial numbers, convert each to device-id
var sernoquery = "id:" + serno;
// Use AdminSDK API to check if the cros device exists. Else the update will fail
var chromebooklist = AdminDirectory.Chromeosdevices.list('my_customer', { query: sernoquery }).chromeosdevices;
if (!chromebooklist) {
} else if (chromebooklist.length !== 1) {
} else {
var id = chromebooklist[0].deviceId;
// For each line, try to update the device with given data, and log the result
try {
AdminDirectory.Chromeosdevices.update({ orgUnitPath: "/_Chromebooks/_deprovisioned_chromebooks", notes: "Deprovisioned" }, 'my_customer', id);
} catch (err) {
return [serno, "couldn't be moved", '#ffc90e'];
}
try {
AdminDirectory.Customer.Devices.Chromeos.issueCommand({ 'commandType': ('REMOTE_POWERWASH') }, 'my_customer', id)
} catch (err) {
return [serno, "couldn't be reset", '#ffc90e'];
}
try {
AdminDirectory.Chromeosdevices.action({ 'action': 'deprovision', 'deprovisionReason': 'retiring_device' }, 'my_customer', id);
// If the update fails for some reason, log the error
} catch (err) {
return [serno, "couldn't be deprovisioned", '#ffc90e'];
}
}
return [serno, "has been moved and deprovisioned, reset requested", '#ba68c8'];
}