Using auto-assign for adding licences is definitely a recommendation.
Meaning you make sure that you put people in OUs and then they get licences automatically.
When you don't want people to have licences anymore, you move them to OUs without auto-assign, and remove the licences, either manually (when you move them), or with gam (since pointing gam at an entire OU is super easy).
Usually, such users should also be suspended, because accounts without licences shouldn't be actively used.
Here is my script which will remove licences from all users in the OU /Suspended, regardless of which licence the user has (which you have to provide when you tell gam to remove a licence).
$ cat bin/delete-enterprise-licences-from-suspended-users-in-OU-Suspended-lomma
#!/bin/bash
# Delete licenses from suspended users in the OU /Suspended in Lomma school district.
# This is where my GAMADV-XTD3 is installed.
GAM=/home/kim/gamadv-xtd3/gam
# I like to log what I'm doing. Every run gets a separate logfile.
LOGFILE=/home/kim/GAM-activities/Lomma/licenses-logfile-$(date +'%Y-%m-%d_%H%M')
# Set the correct section (lomma).
SECTION=lomma
# Which OU should we work with.
OU="/Suspended"
# Select the correct section (lomma).
$GAM select $SECTION save
# This is a long one-liner command!
# Printing all licences for our chosen OU and using that as input for the delete command.
$GAM config csv_output_row_drop_filter Licenses:regex:^$ csv_output_row_filter "orgUnitPath:regex:'${OU}'" print users query "isSuspended=true" licenses fields ou | $GAM redirect csv - multiprocess redirect stdout $LOGFILE redirect stderr stdout csv - gam user ~primaryEmail del license ~Licenses
# Reset the section to the default.
$GAM select default save
--
https://wheretofind.me/@NoSubstitute