Export GAM output to CSV
How GAM print commands produce CSV, how to save or redirect that output, and what to check for encoding, flattened fields and spreadsheet handling before you rely on the file.
GAM is a command-line tool for administering Google Workspace, and getting its output into a CSV file is one of the most common things people use it for. This review explains what the export does to your data, when CSV is the right format, and what to check so the file stays accurate and usable after you open, edit or share it. No version-specific test results were supplied for this article, so command details below are described as general patterns. Confirm them against the documentation for the GAM release you actually run.
Which GAM this covers
"GAM" is also a common abbreviation for Google Ad Manager, whose reports can be downloaded as CSV from its own interface. This article covers the Google Workspace command-line tool, including its widely used forks such as GAMADV-XTD3 and its successor GAM7. If you need Ad Manager report exports, the mechanics here do not apply.
Is exporting to CSV suitable for your use?
CSV is a good fit when you need a tabular record of users, groups, devices, licenses or similar objects to filter, audit, reconcile or feed back into another GAM batch command. The main benefit is that the result is plain, delimited text that spreadsheets, scripts and databases can all read. You can also round-trip it: the same file can drive later bulk changes.
The decisive tradeoff is structure. Directory objects often contain nested or repeating values, such as several email aliases, phone numbers or organization entries. CSV has no native nesting, so these values are spread across numbered columns. The resulting file can be very wide and awkward to read.
Plain console output is the better choice when you are inspecting a single object, troubleshooting interactively, or need the nested layout to understand relationships. GAM's show and info style commands are meant for that kind of reading.
What the export actually changes
In GAM, the distinction that matters most is between command families:
- print commands write rows and columns in CSV form, with a header row naming the fields.
- show and info commands write indented, human-readable text that is not CSV and should not be saved with a .csv extension expecting it to parse.
- Some commands offer both forms, so choosing print over show is usually the first step toward a usable file.
Exporting does not alter anything stored in Google Workspace. It is a read operation that serializes the API response into delimited text. Within the file, four things change compared with the underlying data:
- Nested fields are flattened into dotted, numbered column names, so one user's second alias might appear in a column such as emails.1.address.
- Fields that are empty or absent for a given row appear as empty cells, and the set of columns can differ between runs depending on which fields you request and which objects have data.
- Values containing commas, quotes or line breaks are quoted according to CSV conventions. Quoting changes the stored characters but not the meaning, provided the reading program honors the quotes.
- Boolean, date and numeric values become plain text. Their interpretation depends on whatever program opens the file.
Ways to get the CSV into a file
The simplest approach in any version is to redirect standard output from a print command to a file using your shell:
gam print users > users.csv
GAMADV-XTD3 and GAM7 also provide a built-in redirect that writes CSV output directly to a file. This avoids shell-specific encoding behavior and keeps progress messages out of the data:
gam redirect csv ./users.csv print users
Many print commands also accept a todrive option, which uploads the result to Google Drive as a spreadsheet instead of saving a local file. Whether a given command supports it, and which options control sharing and naming, depends on your version, so check the help output before relying on it.
To limit width and keep the file readable, request only the fields you need rather than all fields. Field selection syntax differs between commands and versions.
Converting to TSV or another delimiter
If a downstream system expects tab-separated values, do not convert by replacing every comma with a tab. That approach breaks any quoted field that contains a comma. Instead, use a CSV-aware tool that parses quoted fields first and then writes tabs. Some GAM variants expose configuration settings for the output delimiter. The supplied material did not confirm the exact setting names, so consult your version's configuration documentation rather than guessing.
Will the file stay readable and usable after sharing?
CSV is plain text, so copying, searching and editing it in a text editor preserves the content exactly. Most problems appear when another program interprets the file. These are the main things to check:
- Encoding: GAM data commonly includes non-ASCII names. If a spreadsheet shows garbled accented or non-Latin characters, the file is usually being read with the wrong encoding. Import it explicitly as UTF-8 rather than double-clicking it.
- Shell redirection on Windows: Windows PowerShell 5.1 writes redirected output as UTF-16 by default, which some tools will not parse as expected. PowerShell 7 defaults to UTF-8 without a byte order mark. GAM's own redirect option sidesteps this difference.
- Spreadsheet auto-conversion: spreadsheet programs may strip leading zeros from IDs, reformat dates or turn long numbers into scientific notation. Import these columns as text if exact values matter.
- Formula interpretation: a cell value beginning with characters such as =, +, - or @ can be treated as a formula when the file is opened in a spreadsheet. Treat exported files from shared or user-editable fields with that in mind.
- Re-importing: if you edit the file and feed it back into a GAM batch command, keep the header names unchanged. GAM matches columns by header.
For accessibility, a CSV opened in a spreadsheet is navigable cell by cell with a screen reader, and the header row supplies column context. Very wide exports with many flattened columns are hard to navigate. Selecting fewer fields helps both sighted and non-sighted readers. No scoped testing with specific assistive technologies was supplied, so behavior in a particular screen reader and spreadsheet combination is unverified here.
Handling the data responsibly
GAM exports often contain personal information about everyone in a domain. A local CSV file, or a spreadsheet uploaded to Drive, sits outside the admin console's access controls. Storage location, sharing settings and deletion therefore become your responsibility. This article does not assess any tool's retention practices. Check your organization's data-handling policy before sharing exports.
Gaps in this review
- No version-specific command reference was supplied, so option names should be verified against your installed GAM release.
- No tests of specific spreadsheet programs, import dialogs or screen readers were provided. Compatibility notes above describe general behavior, not observed results.
- Exact column names produced by each print command vary by command, requested fields and version, and are not listed here.
Bottom line
Use print commands with either GAM's own redirect or a todrive upload when you need tabular, reusable data. Request only the fields you need, and open the file as UTF-8 text-preserving import to keep values intact. Stay with show or info output when you are reading a single record or need its nested structure to make sense of it.