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.
![1. There are two Users 1st is ok sir in CI Org Unit it has Frontline User License Assigned](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda3f_1.-There-are-two-Users-1st-is-ok-sir-in-CI-Org-Unit-it-has-Frontline-User-License-Assigned-1030x579.png)
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.
![3. Lets go to Sheets will Create a Sheet and lets call it a FLW](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda33_3.-Lets-go-to-Sheets-will-Create-a-Sheet-and-lets-call-it-a-FLW-1030x579.png)
Then you will click on extensions, go to Apps script. Under Apps script let's name our sheet (may be flw remove).
![4. Under add Skript Lets name our Sheet may be FLW](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda50_4.-Under-add-Skript-Lets-name-our-Sheet-may-be-FLW-1030x579.png)
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.
![5.Here Delete all the Default Function and Going to paste that Script that copy from the website](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda4d_5.Here-Delete-all-the-Default-Function-and-Going-to-paste-that-Script-that-copy-from-the-website-1030x579.png)
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.
![8. Come Back to this Sheet and Rename it and call it Remove Licenses So it can Find That Sheet and data](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda2b_8.-Come-Back-to-this-Sheet-and-Rename-it-and-call-it-Remove-Licenses-So-it-can-Find-That-Sheet-and-data-1030x579.png)
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.
![9. Under Services Click on Plus you will Find Enterprises License Manager API](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda6e_9.-Under-Services-Click-on-Plus-you-will-Find-Enterprises-License-Manager-API-1030x579.png)
Now, let us run our script by clicking on "Run" button as you see in the screenshot below.
![11. then Click on save and Add it Now Lets Run it this is the First time So Script will ask for Authorization](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda5a_11.-then-Click-on-save-and-Add-it-Now-Lets-Run-it-this-is-the-First-time-So-Script-will-ask-for-Authorization-1030x579.png)
Apps script will need your permission when you run it for the first time, click on review permissions to review.
![12. We Will Approve to Review Permission](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda76_12.-We-Will-Approve-to-Review-Permission-1030x579.png)
Make sure the address you using to authorize the script has required permissions to delete licenses.
![13. Now Give it the Admin Id](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda54_13.-Now-Give-it-the-Admin-Id-1030x579.png)
You can read more about the permissions required by clicking on the bubble icon. If you're satisfied, click allow.
![14. Give the admin Id read more about the Permissions . If You satisfied click On Allow](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda73_14.-Give-the-admin-Id-read-more-about-the-Permissions-.-If-You-satisfied-click-On-Allow-1030x579.png)
Now if you go back to the sheet, you would notice license update status is changed to "License Updated Successfully" or "License Removed Successfully".
![15. Lets Go Back to my Sheet and It said License Updated Successfully](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda38_15.-Lets-Go-Back-to-my-Sheet-and-It-said-License-Updated-Successfully-1030x579.png)
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.
![17. Now See its not Assigned anymore](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda57_17.-Now-See-its-not-Assigned-anymore-1030x579.png)
Same for the second user, Google Workspace frontline license has been removed from this user too, which means our script is working fine.
![19. Lets Look At The Ok the First one Same Process and See Different Line is gone from here Too](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda60_19.-Lets-Look-At-The-Ok-the-First-one-Same-Process-and-See-Different-Line-is-gone-from-here-Too-1030x579.png)
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.
![24. Here You will Find Google Products and SKU ids](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda82_24.-Here-You-will-Find-Google-Products-and-SKU-ids-1030x579.png)
Update the script with it, and that is it.
![26. Now We Just Need to Enter these two Things Product Id And Sku Id](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda79_26.-Now-We-Just-Need-to-Enter-these-two-Things-Product-Id-And-Sku-Id-1030x579.png)
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.
![30. all Those users that we have Put Here With Enterprises License Their License Will be Removed](https://cdn.prod.website-files.com/652583d059964c2e9f5a207f/652ae1c1422fddacbfdfda48_30.-all-Those-users-that-we-have-Put-Here-With-Enterprises-License-Their-License-Will-be-Removed-1030x579.png)
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
....