Google Frontline Worker - Bulk License Assignment (via Apps Script)
https://youtu.be/eoDedGEfdUg
Google Frontline Worker - Bulk License Assignment (via Apps Script)
Hey, Google Admins, this is Goldy again. Welcome back to the Google Frontline Worker SKU video series. In this video I'll talk to you about how you can leverage Google Apps script to bulk assign frontline worker license as to your users.
For that, let me share my screen and let's do this. I have this organizational unit called 'CI only' where I have two users inside.
If I scroll down on user's license section, you will see that this user does not have any license assigned. It is just as cloud identity free user.
My objective is to bulk assign frontline worker SKU to these two users. In your case, there might be hundreds of users, it will still work the same way.
Okay, so let us leverage Google Apps script for this bulk Google Workspace frontline license assignment. You do not need to write the script as I have put it in the blog post below so you can just simply copy and paste it.
To start the process, go to your google sheets, and create a new new sheet, and give it a name (e.g flw license assignment), and then click on the 'Extensions' menu and then click on 'Apps Script' as shown in the screenshot below.
Now, you would see Google Apps script editor page, let us name our script (e.g flw script).
You script will now look like this with the name you gave it, and the default function in there.
Now, copy the script from below code block, remove the default apps script function, and paste this script.
------------------
function assignLicenses() {
// Add SKU details here, below ones are for frontline worker
var productId = "Google-Apps"
var skuId = 1010020030
// Get Google Sheet and read the user emails from it, we'll use these to assign licenses
var assignmentSheet = SpreadsheetApp.getActive().getSheetByName("Assign Frontline Licenses")
var data = assignmentSheet.getRange(2, 1, assignmentSheet.getLastRow() - 1, 2).getValues()
// Create an array to store the results from API, instead of appendRow, we'll rather save output to this array, and then write back to sheet at once
var fileArray = [
["License Assignment Status"]
]
// Loop through the google sheet values, and call License API to assign the given license
data.forEach(function(item) {
var status = "Licese Assigned Successfully"
try {
//var productId = getSkuDetails(item[1])
var apiCall = AdminLicenseManager.LicenseAssignments.insert({
"userId": item[0]
}, productId, skuId)
}
// Catch Errors (if any)
catch (e) {
var status = e.message
}
// Write the output data back to our array
fileArray.push([status])
})
// Write the results from array to our google sheet
assignmentSheet.getRange(1, 2, fileArray.length, fileArray[0].length).setValues(fileArray)
}
--------------------------
Your script will now look like the screenshot below.
This script will read the data from our Google sheet, so make the sheet name in the script (in line number 9) matches your actual google sheet name.
In my script above, the name of the sheet is 'Assign Frontline Licenses', so am giving my google sheet tab the same name as you see in the screenshot below.
Now you can add two columns in this google sheet (i) User Primary Email, and (ii) Status
You should enter the email address of the users in column one (one email per row), and leave the status (second) column blank as our script will output the status here.
Now go back to your Google apps script, on the left navigation, click on services, and scroll down to 'Enterprise License Manager API', add this services as we'll need it to assign google workspace frontline licenses to our users in bulk.
Now we are all set to run our script, click on save to save all changes so far, and then click on play button to run the script as shown below.
As you are running the script for the first time, it will ask for your permissions.
Now, select the admin account to provide permissions, and the script will run.
Once the script runs, it will output the frontline license assignment status to our google sheet as you see below.
Now if I go back to this user in my admin console, I see that the script assigned him a Google Workspace frontline license sku.
I hope it was helpful a bit if you wanted to assign Google Workspace frontline licenses in bulk to your users, if you have any question, comment or feedback, don't hesitate to comment below.
Related Posts
....