Change all Groups Domain name to new Domain

878 views
Skip to first unread message

Stephen Bennett

unread,
Mar 1, 2022, 8:35:36 PM3/1/22
to GAM for Google Workspace
Hi All,

I am trying to work out how i change the Domain name being used in groups.

I was thinking maybe i could run the below to get the groups email

gam print groups > printgroups.csv

Then I was wondering if I could read it and change it to newdomain.com.au

gam csv "printgroups.csv" update group email "~email" "^(.+)@.*$" "\1...@newdomain.com.au"

Any ideas what I am missing?

Regards
Stephen

Maj Marshall Giguere

unread,
Mar 1, 2022, 11:41:49 PM3/1/22
to google-ap...@googlegroups.com
Your first gam command will return a file containing all of the FQDN email addresses of all the groups in the domain, so far so good.
Your second command starts to go off at the "update" token.  It should read "update ~email", that will tell gam which group you want to update.  The remainder will expand into something like "email some...@somedomain.com.au^(.+)@.*$1...@newdomain.com.au".

I suggest a three step approach.  The first command will get you your current set of groups, next you need to pass it through a filter that will output a new csv file with two columns: oldgroup,newgroup and each line maps the old group to the new.  This can be easily accomplished with tools like awk, python, or for the brave bash shell.  I'm not sure what to recommend since the execution environment isn't specified.  Here's an example using a *nix bash environment.

> gam print groups > printgroups.csv
> (echo "oldgroup,newgroup";tail +2 printgroups.csv |gawk -e '{split($1,a,"@",s);print( $1","a[1]"@newdomain.au");}') > updateGroups.csv
> gam csv updateGroups.csv update ~oldgroup email ~newgroup

As noted previously there are other methods, Python to read the initial csv and output a new one.

Hope that's useful,
-Marsh

--
Maj Marshall E Giguere
NH Wing Director of IT
Civil Air Patrol, U.S. Air Force Auxiliary




Volunteers serving America's communities, saving lives, and shaping futures.


--
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/81a4fd36-b3d9-40cc-8913-9cc90f55dd65n%40googlegroups.com.

Ross Scroggs

unread,
Mar 1, 2022, 11:45:54 PM3/1/22
to google-ap...@googlegroups.com
Stephen,

gam print groups > printgroups.csv

open printgroups.csv
copy column A to column B
change the header of column B to newemail
Replace domain.com.au with newdomain.com.au in column B
save printgroupsa.csv

gam csv printgroups.csv gam update group "~email" email "~newemail"

Ross

Stephen Bennett

unread,
Mar 2, 2022, 12:21:45 AM3/2/22
to google-ap...@googlegroups.com

Chris River

unread,
Mar 2, 2022, 2:55:51 PM3/2/22
to GAM for Google Workspace
If you want a one-liner and you're using Advanced GAM:
gam print groups | gam csv - matchfield email "@OLDDOMA.IN$" gam update group ~email email '~~email~!~^(.+)@.*$~!~\1...@NEWDOMA.IN~~'

This uses Advanced GAM's built in substitution syntax (https://github.com/taers232c/GAMADV-XTD3/wiki/Bulk-Processing#csv-files) to do regex replacement of the old domain with the new domain. This command also uses "matchfield" so you can run the command multiple times if needed to reprocess some groups that didn't get renamed the first time around for some reason (API quota limits, etc.).

Stephen Bennett

unread,
Mar 2, 2022, 2:58:01 PM3/2/22
to google-ap...@googlegroups.com
Thanks

I have Advanced GAM, I also have hundreds of groups to do.

Regards
Stephen

Stephen Bennett

unread,
Mar 2, 2022, 3:08:13 PM3/2/22
to google-ap...@googlegroups.com
Thanks for that. 

I will test today.

Regards
Stephen 

On Thu, 3 Mar 2022, 5:55 am Chris River, <chris...@amplifiedit.com> wrote:
Message has been deleted

Stephen Bennett

unread,
Mar 2, 2022, 7:13:31 PM3/2/22
to GAM for Google Workspace
Hi All,

Many thanks for the help, is it possible to delete the group Alias that match a domain name found?

Regards
Stephen

Ross Scroggs

unread,
Mar 2, 2022, 9:58:29 PM3/2/22
to google-ap...@googlegroups.com
Stephen,

Replace domain.com with domain name of aliases to delete

Standard GAM
gam print aliases nousers > groupaliases.csv
export GAM_CSV_ROW_FILTER="Alias:regex:@domain.com$"
Test
gam csv groupaliases.csv gam info alias "~Alias"
Delete
gam csv groupaliases.csv gam delete alias "~TargetType" "~Alias"

Advanced GAM
gam print aliases nousers > groupaliases.csv
Test
gam config csv_input_row_filter "Alias:regex:@domain.com$" csv groupaliases.csv gam info alias "~Alias"
Delete
gam config csv_input_row_filter "Alias:regex:@domain.com$" csv groupaliases.csv gam delete alias "~TargetType" "~Alias"

Ross

Stephen Bennett

unread,
Mar 2, 2022, 10:06:43 PM3/2/22
to GAM for Google Workspace
Thanks heaps :-)
Reply all
Reply to author
Forward
0 new messages