I need to delete role assignments from a list of user accounts. I am familiar with Google Apps Script, but need help working out the script needed to delete the role assignments using the Google Admin API. Has anyone got any examples they could share?
Asked
Active
Viewed 59 times
0
-
Do you want to remove all the roles and custom roles apply to the users? Or specific roles only? – Giselle Valladares May 19 '23 at 17:30
1 Answers
0
I made a sample code that will get all the roles under that user, and after that it will remove them. Take in consideration that you might need to change it base on your user case.
function roles_Assignments_1() {
let user_list = ['user1@domain.com', 'user1@domain.com', 'user1@domain.com']
for (let i = 0; i < user_list.length; i++) {
let roleAssignments_info = AdminDirectory.RoleAssignments
.list("my_customer", { userKey: user_list[i] });
try {
let role_items = roleAssignments_info.items;
for (let j = 0; j < role_items.length; j++) {
let roles_Assignments_ID = role_items[j]['roleAssignmentId'];
AdminDirectory.RoleAssignments.remove('my_customer', roles_Assignments_ID)
}
} catch (err) {
Logger.log("It doesn't have a role")
}
}
}
Reference:

Giselle Valladares
- 2,075
- 1
- 4
- 13