Google Workspace Frontline - Bulk Remove Licenses via Apps Script
Hey Google Admins, this is Goldy again, welcome to Google Workspace Frontline Worker video series.
In this video I'll show you how you can bulk remove Google frontline licenses from your users. maybe you have a lot of attrition or there is a use case where you need to remove frontline worker licenses in bulk. This video might help, we will be leveraging Google Apps script for it.
I'll just show you a static way where you can put the list of users in Google sheet and the script will run picking users one by one to remove their frontline worker license.
So as you see below, I have couple of users in my 'CI Only' organizational unit where I have them assigned Frontline worker license, and I will be using Google Apps script to remove frontline licenses from them.
I'll go to sheets.new to create a new Google sheet, let's call it FLW. You can be more descriptive than what I did here.
Then you will click on extensions, go to Apps script. Under Apps script let's name our sheet (may be flw remove).
https://youtu.be/24CEjmk7fHA
Now delete the default function that you see here, and copy the script below, and then paste it.
-----------------------------------------------------
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)
}
-----------------------------------------------------
It would look like the below screenshot now.
Let's change the sheet name (at the bottom as shown in screenshot below) to "Remove Licenses" as this is what we have in the script, if you want to leave it sheet1 or any other name, then make sure to change it in the script also (watch the video above for more clarity).
Now, add two columns to the sheet (i) User Email Address, and (ii) Status
you would be putting the email address of the users from whom you want frontline license to be removed, you can leave the status column empty as our script will fill it up automatically with the status.
I have only added couple of users for this demonstration, but you may add a few hundreds too.
Now, go back to your Apps Script, click on "Services" on the left, then click on + icon, and add Admin Enterprise License Manager API service (as shown in screenshot below), as we'll use this to remove frontline worker licenses from the given users, finally click on "Add" blue button.
Now, let us run our script by clicking on "Run" button as you see in the screenshot below.
Apps script will need your permission when you run it for the first time, click on review permissions to review.
Make sure the address you using to authorize the script has required permissions to delete licenses.
You can read more about the permissions required by clicking on the bubble icon. If you're satisfied, click allow.
Now if you go back to the sheet, you would notice license update status is changed to "License Updated Successfully" or "License Removed Successfully".
Let us confirm that by looking for these users licenses in Google Workspace admin console, I see that the frontline license has been removed from the user.
Same for the second user, Google Workspace frontline license has been removed from this user too, which means our script is working fine.
Now, actually you can use this script to remove any license from the given users, just by changing couple of properties in the script.
example - go to Google Enterprise license manager API , copy the product and sku-id of the license that you want to remove.
Update the script with it, and that is it.
Then, simply add your users as you did to remove frontline licenses, then run the script and this time it will delete the license that you have put in the script.
I hope that this was helpful to delete Google Workspace Frontline worker license in bulk, in case if you have any questions, comments or feedback do not hesitate to put that below, and i'll be happy to collaborate.
Related Posts
....