Last active
October 11, 2016 16:13
-
-
Save ergosteur/52c9580005311ca73c6fa6eddef0e488 to your computer and use it in GitHub Desktop.
Script to move Chromebooks according to CSV file. Depends on gam.py.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/powershell | |
<# | |
.SYNOPSIS | |
. | |
.DESCRIPTION | |
. | |
.PARAMETER FullInventoryCSV | |
The path to the fully inventory CSV output from GAM.py print cros allfields. CSV must be comma-separated. | |
.PARAMETER LocalInventoryCSV | |
The path to the local school inventory CSV as prepared by the tech. | |
Must have headers serialNumber and notes (case-sensitive). CSV must be comma-separated. | |
.PARAMETER OrgUnitName | |
Organizational Unit in Google Apps. Will be created as /Chromebooks/Ecoles/[OrgUnitName] | |
.EXAMPLE | |
C:\PS> | |
<Description of example> | |
.NOTES | |
Must be placed in a folder with gam.py and run on a machine with Python 2.7 installed - maybe a Linux box with PowerShell ;) | |
Author: Matthieu Yiptong | |
Date: 2016-10-06 | |
#> | |
param ( | |
[Parameter(Mandatory=$True)][string]$FullInventoryCSV, #= './chromebooks_2016-10-05_less.csv', #headers as output by gam - deviceId, annotatedUser, serialNumber, model, notes, orgUnitPath | |
[Parameter(Mandatory=$True)][string]$LocalInventoryCSV, #= './esmdc.csv', #headers notes, serialNumber | |
[Parameter(Mandatory=$True)][string]$OrgUnitName #= 'ESMDC' #Case sensitive | |
) | |
if($FullInventoryCSV -eq "fetch") { | |
$gamCSV=& ./gam.py print cros allfields | |
$allChromebooks=ConvertFrom-Csv $gamCSV | |
} | |
Else { | |
$allChromebooks=import-csv $FullInventoryCSV | |
} | |
$scannedList=import-csv $LocalInventoryCSV | |
$outputCSV="$OrgUnitName-updated.csv" | |
$scannedList | ForEach-Object { | |
$currentSerial = $_.serialNumber | |
$currentDevice = $allChromebooks | Where-Object {$_.serialNumber -eq $currentSerial} | |
if($currentDevice) { | |
$currentDevice.notes = $_.notes | |
$currentDevice.orgUnitPath = "/Chromebooks/Ecoles/$OrgUnitName" | |
$currentDevice | ft serialNumber,annotatedUser,notes,orgUnitPath | |
} | |
} | |
$updatedChromebooks = $allChromebooks | Where-Object {$_.serialNumber -in $scannedList.serialNumber} | |
$updatedChromebooks | ft deviceID,annotatedUser,serialNumber,model,notes,orgUnitPath | |
$updatedChromebooks | export-csv -notype -Path $outputCSV #Notype prevents a header line from being written to the CSV | |
Write-Host "Please verify $outputCSV is correct, then press any key to continue or 'Ctrl-C, Enter' to cancel" | |
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | |
python ./gam.py create org $OrgUnitName parent /Chromebooks/Ecoles | |
python ./gam.py create org $OrgUnitName parent '/Chromebooks/Kiosk mode OQRE' | |
python ./gam.py csv $outputCSV gam update cros ~deviceId user ~annotatedUser location ~annotatedLocation notes ~notes ou ~orgUnitPath assetId ~annotatedAssetId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment