-
Notifications
You must be signed in to change notification settings - Fork 3
/
CB_Activity.gs
52 lines (49 loc) · 2.24 KB
/
CB_Activity.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
List Org Unit, Chrome Device Serial Number, OS Version, Most Recent User,Last Sync, Status, MAC, Recent Activity, AUE to Sheet and sort by OU.
Also, in the Sheet in cell J1 I put =NOW() and in J2 I put this to calculate how many days since last sync.
=ARRAYFORMULA(IF(LEN(A2:A);DATEDIF(LEFT(D2:D;10);J1;"D");))
I then colour code that with conditional formatting.
*/
function listCrOS()
{
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Devices');
var deviceArray = [["Org Unit Path","Serial Number","Most Recent User","Last Sync", "Recent Activity", "Status","OS Version", "MAC", "AUE"]];
var pageToken, page;
do
{
var response = AdminDirectory.Chromeosdevices.list('my_customer',{ pageToken: pageToken});
var devices = response.chromeosdevices;
if (devices && devices.length > 0) {
for (i = 0; i < devices.length; i++) {
var device = devices[i];
if (device.recentUsers && device.recentUsers[0].email) {
var recentUser = device.recentUsers[0].email} else {var recentUser = ""};
if (device.activeTimeRanges && device.activeTimeRanges.length > 0) {
var lastAT = (device.activeTimeRanges.length-1)
var activeTimes = (device.activeTimeRanges[lastAT].activeTime/60000)
var activeTime = Math.ceil(activeTimes)
var activeTimeRanges = device.activeTimeRanges[lastAT].date + " " + activeTime + "min"
} else {var activeTimeRanges = ""};
if (device.lastSync) {
// Format lastSync to only show first 10 characters and replace T with space, to separate date and time.
var lastSync = device.lastSync.substring(0, 10).replace(/T/g, " ")} else {var lastSync = ""};
{
deviceArray.push([device.orgUnitPath, device.serialNumber, recentUser, lastSync, activeTimeRanges, device.status, device.osVersion, device.macAddress, device.autoUpdateExpiration]);
}
}
}
pageToken = response.nextPageToken;
}
while(pageToken);
sheet.getRange(1, 1, deviceArray.length, 9).setValues(deviceArray);
var range = sheet.getRange("A2:I");
range.sort(1);
// Set the format of columns E and H to text, so its values aren't considered to be date objects.
// Single column
var column = sheet.getRange("D2:D");
// Simple text format
column.setNumberFormat("@");
var column = sheet.getRange("E2:E");
// Simple text format
column.setNumberFormat("@");
}