Administering Google Workspace GAM7
Administering Google Workspace with GAM7
Input: "List files shared with 'anyone with the link' for every user in OU /Ventas, into one CSV."
gam config auto_batch_min 1 redirect csv ./AnyoneShares.csv multiprocess ou /Ventas print filelist fields id,name,permissions pm type anyone em
Output: AnyoneShares.csv with columns Owner,id,name,permissions... (one row per matching file, all users merged).
Flags: auto_batch_min 1 runs one subprocess per user; redirect csv ... multiprocess merges every subprocess into one file; ou /Ventas selects users directly in that OU (ou_and_children adds sub-OUs); pm type anyone em opens/closes a permission match.
Validated against: GamCommands.txt (main) · wiki: Bulk-Processing, Permission-Matches
GAM7 releases weekly and shares its codebase and gam.cfg with GAMADV-XTD3 (7.00.00 = "Merged GAM-Team version"). XTD3 syntax still present in current docs is valid GAM7. Never use Legacy GAM syntax (the pre-merge GAM-team branch). Never trust memory for flags: confirm each keyword in the current GamCommands.txt or the wiki.
Use the bundled helper scripts/gam7ref.py (stdlib-only Python 3; python on Windows; caches the official docs 12 h):
Bashpython3 scripts/gam7ref.py cmd "print filelist" "showownedby" # BNF blocks containing ALL terms python3 scripts/gam7ref.py def DriveFileEntity # expand a <NonTerminal> python3 scripts/gam7ref.py wiki Users-Drive-Permissions --grep "delete drivefileacl" python3 scripts/gam7ref.py since "addlabelid" # estimated minimum version python3 scripts/gam7ref.py wikigrep "orphans" # which wiki page documents a term python3 scripts/gam7ref.py version # latest documented version
Fallbacks if the script cannot run:
- Shell:
curl -sSL https://raw.githubusercontent.com/GAM-team/GAM/main/src/GamCommands.txt -o GamCommands.txtthengrep -n -A10 "^gam .*print filelist" GamCommands.txt - No shell:
WebFetchonhttps://raw.githubusercontent.com/wiki/GAM-team/GAM/<Page>.md - No network: deliver the command marked "not validated in this session" and list what to verify.
Progress:
- [ ] 1. Locate the BNF block with `cmd`; every keyword must appear in it
- [ ] 2. Expand non-terminals with `def` (user selectors, field lists, matches)
- [ ] 3. Read the wiki page for defaults and official examples
- [ ] 4. Check `since`; if keyword is 7.4x+, add "requires GAM7 >= X (`gam version simple`)"
- [ ] 5. Edge cases: search site:groups.google.com/g/google-apps-manager (secondary source; docs win on conflict)
- [ ] 6. Not supported? Say so first, then give the closest alternative
- [ ] 7. Deliver: command, flag breakdown, provenance line
Step 6 wording: "Not natively supported by GAM7 (absent from GamCommands.txt and the wiki)", followed by the nearest GAM command, console path, direct API call, Apps Script or gcloud. Never invent a flag.
Topic → wiki page map: references/wiki-index.md.
- Lead with the command or script. No preamble, no restating the question.
- GAM commands without a named shell: bare code block, no inline comments (
#is not a comment in CMD). Explanation goes in the breakdown. - Scripts (only when a shell is named): language-tagged block (
powershell,bat,bash) with heavy comments. - After the block: flag breakdown, one line per flag. Then a few lines on any non-trivial filter/parallel logic.
- Repetitive task → show CSV header + 1-2 sample rows and the
gam csvcommand that consumes it. - Destructive operations (delete, remove, suspend, wipe, purge, transfer): deliver exactly the requested command; the breakdown still explains flags such as
doit. - Close with:
Validated against: GamCommands.txt (main) · GAM7 <version> · wiki: <Page> - Spanish prose when the user writes Spanish; commands and flags verbatim from docs.
Example 1: Bulk create users from CSV
Input: "Create these users in OU /Soporte: users.csv has primaryEmail,givenName,familyName,password."
gam csv users.csv gam create user "~primaryEmail" firstname "~givenName" lastname "~familyName" password "~password" changepassword on org /Soporte
Breakdown: gam csv runs one gam per row (5 parallel by default, num_threads); "~col" substitutes the CSV column (quoted to survive ~); changepassword on forces a reset at first login; org sets the OU.
Output: one User: x@dominio.com, Created line per row.
Example 2: Offboarding checklist
Input: "Offboard jperez@dominio.com: suspend, remove from groups, transfer Drive to msilva, set vacation reply."
Progress:
- [ ] Suspend
- [ ] Remove from all groups
- [ ] Transfer Drive
- [ ] Vacation responder
- [ ] Verify
gam update user jperez@dominio.com suspended on
gam user jperez@dominio.com delete groups
gam user jperez@dominio.com transfer drive msilva@dominio.com
gam user jperez@dominio.com vacation on subject "Ya no trabaja aqui" message "Contacte a msilva@dominio.com"
gam info user jperez@dominio.com
Breakdown: suspended on blocks sign-in; delete groups removes memberships; transfer drive moves owned files; vacation on sets the auto-reply; info user confirms final state. Validate each against cmd (e.g. gam7ref.py cmd "transfer drive") before delivery, since transfer options vary by version.
Example 3: Failure case: quota error in bulk run
Input: "Running gam csv over 40,000 users, I see Got HTTP response code 429: rateLimitExceeded and slow retries."
Diagnosis: concurrency exceeds the project quota. Fix:
gam config num_threads 5 csv users.csv gam user "~email" print filelist fields id,name redirect csv ./files.csv multiprocess
Breakdown: lower num_threads (default 5) to reduce parallel API calls; GAM already retries with backoff, so do not wrap it in external parallelism (workers × num_threads multiplies calls against the same quota).
Example 4: Unsupported request
Input: "Change the Gmail 'smart reply' admin default for all users."
Output: "Not natively supported by GAM7 for this setting (absent from GamCommands.txt). Alternative: Admin console → Apps → Google Workspace → Gmail → User settings. For Cloud Identity policies GAM7 offers gam print|show|info policies; confirm with gam7ref.py wiki Cloud-Identity-Policies whether this policy type is modifiable before claiming it."
- No shell named → GAM7 commands only; loop with
gam csv,gam loop,gam batch|tbatch,redirect ... multiprocess. Keep them shell-neutral: double quotes around args with spaces or~ | > < &; use GAMredirect csv|stdout|stderr, never shell>; note when\"(Linux/macOS/CMD) differs from PowerShell's`"and when regex backslashes in row filters differ (\\\Linux/macOS,\\Windows). - Shell named (PowerShell, Batch, Bash) → use that shell and read
references/shells.md(official escaping rules, commented templates). Bare "PowerShell" = PowerShell 7 (#Requires -Version 7.0,ForEach-Object -Parallel); do not use it for 5.1.
Parallelize from most to least native:
gam csvwithredirect csv <file> multiprocess(num_threads, default 5).config auto_batch_min Nforgam <UserTypeEntity> ...on large collections, no CSV needed.gam batch(processes; cannot containgam csv) orgam tbatch(threads; can).- External parallelism (
ForEach-Object -Parallel,xargs -P) only for multi-tenant/multi-gam.cfgsection jobs or non-GAM steps. Use thread-safe collections, explicit-ThrottleLimit, absolute paths, and check eachgamexit code.
Design for unattended runs: no prompts (commit-batch without text, since commit-batch <Text> waits for a keypress), output via redirect, check return codes.
Filter closest to the source:
- API:
query/queries, Drivequery/fullquery, minimalfields. - GAM output:
config csv_output_row_filter,csv_output_row_drop_filter(+_mode),csv_output_header_filter,csv_output_header_drop_filter,csv_output_row_limit; reusable viaselectfilter. gam csvinput:matchfield/skipfield,skiprows/maxrows,csv_input_row_filter.
Row-filter quoting is strict: list in ", each field:filter pair in ', and \" around names containing : or spaces. Full syntax, select, multiprocessexit, gam.cfg performance variables, filter types and return codes: references/lotes-y-filtros.md.
- Run the destructive command's
print/showcounterpart first when the user did not ask for the destructive form only (e.g.gam ou /X print filelistbefore a mass change); when they asked for the destructive command, give it as requested. - Use
ouvsou_and_childrendeliberately; confirm withdef UserTypeEntity. - Keep
fieldsminimal; large-domain runs (10k+ users) should useredirect csv ... multiprocessinstead of one giant sequential call, which also avoids memory growth and API pagination stalls. - Name outputs per run (
./reports/Shares-$(date).csvvia shell, or fixed names withredirect csv ... append). - Always note minimum version for recent keywords.
- Inventing flags from Legacy GAM or half-remembered XTD3 syntax. Always
cmdfirst. - Writing
>for output in neutral commands; useredirect. - Putting
gam csvinsidegam batch(unsupported; usetbatch). - Unquoted
"~column"references, breaking on spaces or special characters. commit-batch "text"in scheduled jobs (hangs waiting for a key).- Stacking external parallelism on top of
gam csv(429 errors from multiplied concurrency). - Using
ouwhen sub-OUs were intended (or the reverse). - Claiming a console setting is scriptable without confirming it in
GamCommands.txtor the wiki. - Row-filter quoting mistakes (missing
'pairs, unescaped:in header names).
scripts/gam7ref.py: doc lookup helper (must ship alongside this file)references/lotes-y-filtros.md: bulk processing,redirect, meta commands,gam.cfgperformance variables, filters, return codesreferences/shells.md: per-shell escaping and commented PowerShell 7 / 5.1 / Batch / Bash templatesreferences/wiki-index.md: Workspace topic → wiki page map