Export Users using a specific domain alias

1,228 views
Skip to first unread message

Sean Waite

unread,
Oct 28, 2021, 12:05:39 PM10/28/21
to GAM for Google Workspace
Is there a way to export users with a specific domain alias?

For example, the primary domain is foo.com and secondary domain is bar.com - how to search for users who have bar.com as an alias on their account (when foo.com is their primary email ID).

We have over 100 secondary domains so I am trying to find a subset of users with a specific domain alias on their account - without having to export all users as there as some 160k+. This is in preparation for removing the secondary domain from the tenant.

Thanks!

Ross Scroggs

unread,
Oct 28, 2021, 12:23:17 PM10/28/21
to google-ap...@googlegroups.com
Sean,

Try this:

gam config csv_output_row_filter "aliases.*:regex:.*@bar.com" print users domain foo.com aliases


Ross



Verizon UK Limited - registered in England & Wales - registered number 2776038 - registered office at Reading International Business Park, Basingstoke Road, Reading, Berkshire, UK RG2 6DA - VAT number 823 8170 33

--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/fcad261a-e6b7-4c11-880c-00b40b5ae4d6n%40googlegroups.com.


--

Sean Waite

unread,
Oct 28, 2021, 4:46:56 PM10/28/21
to GAM for Google Workspace
Thanks Ross!

Chris River

unread,
Oct 29, 2021, 11:48:46 AM10/29/21
to GAM for Google Workspace
A more efficient way to do it is to have Google perform the query on their end (remove "aliases" if you only need the primary address):
gam print users query email:bar.com aliases

I usually want to be extra certain that I've captured all aliases, and I usually want to delete the aliases, so I typically let GAM query all users (and groups) via this command:
gam config csv_output_row_filter "Alias:regex:.*@bar.com" print aliases

To delete all aliases at the old domain, I run this command:
gam print aliases | gam csv - matchfield Alias "@bar.com$" gam delete alias ~TargetType ~Alias

Note that you may need to run that command multiple times to delete all aliases. If users have multiple aliases at the old "bar.com" domain, gam will give an error as you can't delete multiple aliases at once (at least, not in the way gam is doing it in that command), so running the command multiple times will clear out these extra aliases. If some users have many aliases at the old domain (it's possible to have 25 or so aliases), then you can change the "gam csv" to "gam loop" for gam to run single-threaded, so you don't have to wait for gam to get a list of all 160k+ users more than is really necessary.

Also, I've found that the Google API is slow for deleting aliases, I seem to run into quota limits much more often when deleting aliases than I do for other Admin SDK quotas, even with Admin SDK quota limits higher than default. So if there are a lot of these to delete, be prepared for that.

Ross Scroggs

unread,
Oct 29, 2021, 2:36:12 PM10/29/21
to google-ap...@googlegroups.com
Chris,

You can avoid the errors by deleting the aliases serially:
gam print aliases | gam config num_threads 1 csv - matchfield Alias "@bar.com$" gam delete alias ~TargetType ~Alias

Ross




--

Chris River

unread,
Oct 29, 2021, 3:41:12 PM10/29/21
to google-ap...@googlegroups.com
Yeah, I mentioned "gam loop", which I find to be an easy way to do "gam config num_threads 1 csv". My mention of this is a bit buried in that paragraph though, so it's easy to miss. :)

Thanks,
Chris



Chris River

Cloud Architect

757-542-5139

Pronouns: He/Him

Meet with me


twitter icon small.png



You received this message because you are subscribed to a topic in the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-manager/QaW7sgybdas/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/CAJkvRS9qF6G869viNSky-XOjwHhF28UhigQHEh72gxCaZXSirw%40mail.gmail.com.

Brian Kim

unread,
Nov 2, 2021, 9:02:55 PM11/2/21
to GAM for Google Workspace
not sure if there is performance benefits but i use aliasmatchpattern. Thanks for the tip about gam loop. Used csv, batch, tbatch but can't say i've used loop yet. Piping (saving at least one copy of the actual CSV for your rollback plan) and re-running is probably the best.

gam print aliases aliasmatchpattern .+@secondarydomain.com

Raju Vemula

unread,
Mar 19, 2025, 8:52:19 AMMar 19
to GAM for Google Workspace
Thanks a ton..!!! Ross..!!

gam print aliases | gam config num_threads 1 csv - matchfield Alias "@bar.com$" gam delete alias ~TargetType ~Alias

this worked for me like a charm, you saved my day

very much thankful for your extended support.
Reply all
Reply to author
Forward
0 new messages