Scripts for auditing and managing Google Workspace environments using GAM7, a command-line tool for Google Workspace administrators.
- Prerequisites
- Quick Start
- Manual Setup
- Verifying the Connection
- Running Scripts
- Useful GAM Commands Reference
- Script Index
- Future Enhancements
- Resources
- Google Workspace — Paid, Education, or Non-profit edition (Legacy Free has limited API support)
- Super Admin access — Required for initial setup (project creation and domain-wide delegation)
- Windows workstation — GAM runs locally from the technician's machine
Run Initialize GAM.ps1 once per customer workspace:
.\"Initialize GAM.ps1" -AdminEmail admin@customer.comThe script handles the full setup end-to-end:
- Installs GAM7 via winget (if not already installed)
- Creates config directories and sets environment variables
- Initializes the GAM config file
- Guides you through GCP project creation (browser-based)
- Authorizes OAuth client scopes (browser-based)
- Configures service account domain-wide delegation (requires a step in Google Admin Console)
- Saves the customer ID and domain to your GAM config
After it completes, run gam info domain to verify the connection.
For stepwise control or to troubleshoot a failed initialization.
Initialize GAM.ps1performs all of these steps automatically.
winget install --id GAM-Team.gam --accept-package-agreements --accept-source-agreementsThis installs GAM7 to C:\GAM7 and registers gam on your PATH. Restart your terminal after install.
- Download the latest MSI from the GAM7 Releases page
- Run the installer — it defaults to
C:\GAM7 - The installer will prompt you to begin setup
pip install gam7
mkdir C:\GAMConfig
mkdir C:\GAMWork
Open System Properties > Environment Variables and add:
| Variable | Value |
|---|---|
GAMCFGDIR |
C:\GAMConfig |
Also add C:\GAM7 to the system Path.
Restart your terminal after making these changes.
gam config drive_dir C:\GAMWork verify
This creates the config file at C:\GAMConfig\gam.cfg.
gam create project
This will:
- Prompt for your Google Workspace admin email
- Open a browser for Google authentication
- Create a GCP project and enable 23 Google APIs (Admin, Drive, Gmail, Calendar, etc.)
- Generate a service account with a private key
- Prompt you to create an OAuth client ID in the GCP Console:
- Go to the URL shown in the output
- Choose Desktop App for Application type
- Name it GAM
- Copy the Client ID and Client Secret back into the terminal
gam oauth create
- Accept the default scope selections (press
cto continue) - Enter your admin email when prompted
- Complete the browser-based authorization flow
gam user your-admin@yourdomain.com update serviceaccount
- Accept the default scope selections (press
cto continue) - The first run will show all scopes as FAIL — this is expected
- GAM provides a link to the Google Admin Console > Security > API Controls > Domain-wide Delegation page
- Click the link, ensure Overwrite existing client ID is checked, and click AUTHORIZE
- Wait a few minutes, then verify:
gam user your-admin@yourdomain.com check serviceaccount
All scopes should show PASS.
gam info domain
Note your Customer ID (e.g., C01234567) and Primary Domain, then:
gam config customer_id C01234567 domain yourdomain.com timezone local save verify
Test that GAM can reach your workspace:
# Show domain info
gam info domain
# List first 5 users
gam print users maxresults 5
# Show your own Drive file count
gam user your-admin@yourdomain.com show filecounts
If these commands return data, GAM is fully connected.
Scripts in this folder are PowerShell wrappers around GAM commands, run interactively from a technician workstation. They assume gam is on your system Path.
# Example: Audit a shared folder's structure
.\Audit Shared Drive Folder.ps1 -UserEmail admin@yourdomain.com -FolderName "Shared Documents"Each script includes comment-based help. Run Get-Help .\ScriptName.ps1 -Full for detailed usage.
# List all files in a user's Drive
gam user user@domain.com print filelist fields id,name,mimetype,size,owners.emailaddress
# List files in a specific folder (recursive)
gam user user@domain.com print filelist select drivefilename "Folder Name" fields id,name,mimetype,size,owners.emailaddress fullpath
# List files with permissions visible
gam user user@domain.com print filelist fields id,name,basicpermissions fullpath# Full disk usage tree for a user's My Drive
gam user user@domain.com print diskusage mydrive
# Disk usage for a specific Shared Drive
gam user user@domain.com print diskusage shareddriveid 0AL5LiIe4dqxZUk9PVA
# Disk usage for a specific folder by name
gam user user@domain.com print diskusage drivefilename "Folder Name"# Show sharing breakdown (internal/external) for a user's files
gam user user@domain.com show filesharecounts
# Print sharing breakdown as CSV
gam user user@domain.com print filesharecounts# Show folder tree structure
gam user user@domain.com show filetree select drivefilename "Folder Name" depth 2 fields id,mimetype
# Print file tree as CSV
gam user user@domain.com print filetree select drivefilename "Folder Name" fields id,mimetype| Script | Purpose |
|---|---|
Initialize GAM.ps1 |
One-time setup of GAM7 for a Google Workspace tenant |
Audit Shared Drive Folder.ps1 |
Audits a Google Drive folder structure for migration planning |
Audit Google Groups.ps1 |
Inventories every Google Group for security review |
Initialize GAM.ps1 - One-time setup of GAM7 for a Google Workspace tenant: installs GAM, sets up directories and environment variables, creates a GCP project, authorizes OAuth and domain-wide delegation, and saves the customer config.
Audit Shared Drive Folder.ps1 - Audits a Google Drive folder for subfolder counts, file counts, external ownership, external sharing, and total sizes - outputs four reports (Summary, FolderDetails, FileDetails, FolderTree) for migration planning. Streams output per-subtree to disk with a 30-second heartbeat, checkpoints to audit.state.json, and supports -Resume / -Restart so multi-hour walks survive Ctrl+C, reboot, or network drops. Automatically detects legacy resource key-protected folders and prompts for the owner's email to impersonate.
See Audit Shared Drive Folder - Guide.md for full usage instructions, a complete column reference for each output file, and data interpretation guidance.
Audit Google Groups.ps1 - Inventories every Google Group in a tenant for security review. Classifies each group as Security, Email (distribution), or Both via Cloud Identity labels; captures owner and manager email addresses, internal vs external member counts, and access settings (whoCanJoin, whoCanPostMessage, allowExternalMembers, etc.); and emits risk flags for owner-less groups, external members, externally-owned groups, public-join, public-post, security groups containing external members, and nested-group references. Outputs GroupMembers.csv (primary CSV with Group Name, Group Email, Group Type, Member Name, Member Email, Role, NestedVia), Groups.csv, GroupTree.txt (visual tree of every group with members listed beneath, role-sorted, externals marked), and Summary.txt (tenant-wide statistics).
Ideas for extending the group audit scripts. These are not yet implemented.
| Idea | Description |
|---|---|
| External-domain frequency table | Group external-member emails by domain to surface vendor/contractor patterns and shadow-IT integrations - helps identify which third-party domains have broad recurring access |
| Permission impact for security groups | Cross-reference Security-type groups against Drive ACLs (reuse FileDetails.csv from the Drive audit) to show which files each security group grants access to |
| Diff / change detection mode | -CompareTo <previous output dir> to flag added/removed groups and membership changes between audit runs |
| Nesting depth report | When -ExpandNestedGroups is on, record each transitively-included member's nesting depth so deeply chained groups that obscure true access are surfaced |
| Mail-flow risk overlay | Combine messageModerationLevel and whoCanPostMessage settings with mailbox forwarding data to flag external-receivable, no-moderation groups - a common phishing pivot |
| Owner-less stale group cleanup report | Cross-reference Risk_NoOwners groups against group last-activity date (requires Reports API) to flag orphaned groups that have also gone unused and are candidates for deletion |