Updating email address for all users in an OU

372 views
Skip to first unread message

Menko Johnson

unread,
May 24, 2018, 6:31:17 PM5/24/18
to GAM for G Suite
Hi there,

I am trying to use GAM to update all student users in particular OU's to have a new username, and delete the alias to the old username.  Here's how our data is setup for each of our 5 schools:

OU: /Students/SCHOOL/GRADYEAR
Email: flastname123@...


What I am trying to do is query all users in the GRADYEAR OU (eg: 2018), and then mass rename them to have Email_GRAD as their new email address. I can query each school's OU succesfully, but don't know how to do the update to add the _GRAD to the end dynamically.  

gam print users query "orgUnitPath='/Students/School/2018’” | gam csv - gam update user ~primaryEmail ~primaryEmail_GRAD


Also, if its possible to query dynamic org units, I could find *2018 for all 5 schools at one time.


Any help on either of those is great.  Otherwise I can go back to CONCATENTATE transforms in the CSV file into a new ~primaryEmail, but this seemed much quicker if it was possible to do.


thanks!



Ross Scroggs

unread,
May 24, 2018, 7:56:12 PM5/24/18
to google-ap...@googlegroups.com
Menko,

Neither standard Gam or my advanced Gam have the ability to do what you want. You need two columns in your CSV file.

gam print users query "orgUnitPath='/Students/School/2018’” > Grads.csv
 
One approach, mostly to illustrate how to combine a column value with other data.
primaryEmail,primaryUser
...
gam csv Grads.csv gam update user ~primaryEmail email ~~primaryUser~~_GR...@domain.com

You approach:
primaryEmail,newPrimaryEmail
...
gam csv Grads.csv gam update user ~primaryEmail email ~newPrimaryEmail

Then you can do:
gam csv Grads.csv gam delete alias user ~primaryEmail

I'll look into making a primitive regex replacement for new emails:
updateemail <Data> <RegularExpression> <Replacement>
The <RegularExpression> will be matched against <Data> and the <Replacement> is built from the matching subfields.
Your case:
gam csv Grads.csv gam update user ~primaryEmail updateemail ~primaryEmail "^(.+)@(.+)$" "\1_GRAD@\2"
Unrelated case, you want the new email address to be flas...@domain.com
gam csv Grads.csv gam update user ~primaryEmail updateemail "~~name.givenName~~+~~name.familyName~~" "^(.).*\+(.+)" "\1\2...@domain.com"

I'm not clear on this question: Also, if its possible to query dynamic org units, I could find *2018 for all 5 schools at one time.
Do you mean you have these OUs: /Students/School1/2018,/Students/School2/2018,/Students/School3/2018,/Students/School4/2018,/Students/School5/2018

If so, with my Advanced Gam you could get the students from all five schools in a couple of ways:
gam redirect csv Grads.csv ous "/Students/School1/2018,/Students/School2/2018,/Students/School3/2018,/Students/School4/2018,/Students/School5/2018" print users primaryemail

Make a csv file Schools.csv with one column School
School
School1
School2
School3
School4
School5

gam redirect csv Grads.csv multiprocess csv Schools.csv gam ou "/Students/~~School~~/2018" print users primaryemail

Ross

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/450d70b9-4958-439f-a4c9-340180e11e13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

✉ Kevin Melillo

unread,
May 25, 2018, 9:12:31 AM5/25/18
to google-ap...@googlegroups.com
Quick question:  Are you doing this in Windows PowerShell, or Bash?  If Bash, I may have something that can assist.

have a csv flle with their email addresses.  You can get this via GAM and a query of the OU.  I believe you already have this step figured out.

Next, run a batch file which will take their email address, strip the domain off to a variable, strip the prefix as the username.  It will do this, and other commands for each name in the list..  see the below

#!/bin/bash
INPUT=~/emails_to_grad.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read userEmail
do
  suffix="_GRAD"
  domain=${userEmail/*@/ }
  userId=${userEmail/@*/ }
  userId="$(echo -e "${userId}" | sed -e 's/[[:space:]]*$//')"
  domain="$(echo -e "${domain}" | sed -e 's/^[[:space:]]*//')"
  domain="@$domain"
  newEmail=$userId$suffix$domain
  ~/bin/gam/gam update user $userEmail email $newEmail
  ~/bin/gam/gam update user $userEmail org "/STUDENTS/GRADS"
done < $INPUT
IFS=$OLDIFS

I added a command in there to switch the ORG, just in case you do that as well...  Please check the code, as I pretty much ripped and changed one of my 
scripts for this...



  
  


For more options, visit https://groups.google.com/d/optout.


--
Kevin Melillo
Electronic Communications Analyst
Information Technology
445 Hoes Lane
Piscataway, NJ 08854

Phone:732-465-6609 | Mobile: 732-609-4331

Ross Scroggs

unread,
May 25, 2018, 10:57:00 AM5/25/18
to google-ap...@googlegroups.com
Menko,

I added a simplification of the option I proposed yesterday; see https://github.com/taers232c/GAMADV-X/wiki/GAM-Updates

gam ou /Students/School/2018 update user updateprimaryemail "^(.+)@(.+)$" "\1_grad@\2"

Ross



For more options, visit https://groups.google.com/d/optout.


--

Menko Johnson

unread,
May 25, 2018, 4:04:51 PM5/25/18
to GAM for G Suite
Thanks Kevin, I'm using BASH, so I'll give that a try.  That looks to be exactly what I wanted. I was also going to update their OU, strip the alias, etc, so I think I can muddle through the script to add those parts and test it out.  You're awesome!

@Ross, awesome, that's close.  As you surmised, yes, I have the same OU name (2018) under each school.  Eg: Students/AHS/2018, Students/BHS/2018.  If I could wildcard /Students/SchoolNames part that would be nice.  But I can just use your new fancy command and do it for 5 schools and be done too!  Thanks so much!  

I realized today one problem with the naming scheme.  In searching the admin console *grad* does not find users with _grad at the end, but if I changed it to grad_username I can find all of them with grad* so I can just change the update to gam ou /Path/To/Ou update user updateprimaryemail "^(.+)@(.+)$" "\grad_1@\2" to work that way.  So cool.  Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.


--

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.


--
Kevin Melillo
Electronic Communications Analyst
Information Technology
445 Hoes Lane
Piscataway, NJ 08854

Phone:732-465-6609 | Mobile: 732-609-4331

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.


--

Ross Scroggs

unread,
May 25, 2018, 4:11:40 PM5/25/18
to google-ap...@googlegroups.com
Menko,

You really want: gam ou /Path/To/Ou update user updateprimaryemail "^(.+)@(.+)$" "grad_\1@\2"
That's grad_ + the 1st sub match (\1) + @ + the 2nd sub match (\2)

But wait, that's more complicated than necessary; all you want is grad_ + the existing email address
gam ou /Path/To/Ou update user updateprimaryemail "^(.+)$" "grad_\1"

Ross

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.


--

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.


--
Kevin Melillo
Electronic Communications Analyst
Information Technology
445 Hoes Lane
Piscataway, NJ 08854

Phone:732-465-6609 | Mobile: 732-609-4331

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.


--

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.

To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-manager.

For more options, visit https://groups.google.com/d/optout.


--

Johnson, Menko

unread,
May 25, 2018, 5:59:03 PM5/25/18
to google-ap...@googlegroups.com
Thanks guys, I’m in good shape! Much appreciated!

Menko
---------
Menko Johnson
Educational Technology Coordinator
Fremont Union High School District
(408) 522-2270

Join our FUHSD Technology Learning Community<https://plus.google.com/u/0/communities/108140751450238103318>

follow @fuhsdstatus for network updates



On May 25, 2018, at 1:11 PM, Ross Scroggs <ross.s...@gmail.com<mailto:ross.s...@gmail.com>> wrote:

Menko,

You really want: gam ou /Path/To/Ou update user updateprimaryemail "^(.+)@(.+)$" "grad_\1@\2"
That's grad_ + the 1st sub match (\1) + @ + the 2nd sub match (\2)

But wait, that's more complicated than necessary; all you want is grad_ + the existing email address
gam ou /Path/To/Ou update user updateprimaryemail "^(.+)$" "grad_\1"

Ross

On Fri, May 25, 2018 at 1:04 PM Menko Johnson <menko_...@fuhsd.org<mailto:menko_...@fuhsd.org>> wrote:
Thanks Kevin, I'm using BASH, so I'll give that a try. That looks to be exactly what I wanted. I was also going to update their OU, strip the alias, etc, so I think I can muddle through the script to add those parts and test it out. You're awesome!

@Ross, awesome, that's close. As you surmised, yes, I have the same OU name (2018) under each school. Eg: Students/AHS/2018, Students/BHS/2018. If I could wildcard /Students/SchoolNames part that would be nice. But I can just use your new fancy command and do it for 5 schools and be done too! Thanks so much!

I realized today one problem with the naming scheme. In searching the admin console *grad* does not find users with _grad at the end, but if I changed it to grad_username I can find all of them with grad* so I can just change the update to gam ou /Path/To/Ou update user updateprimaryemail "^(.+)@(.+)$" "\grad_1@\2" to work that way. So cool. Thanks!


On Friday, May 25, 2018 at 7:57:00 AM UTC-7, Ross Scroggs wrote:
Menko,

I added a simplification of the option I proposed yesterday; see https://github.com/taers232c/GAMADV-X/wiki/GAM-Updates<https://github.com/taers232c/GAMADV-XTD/wiki/GAM-Updates>
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/450d70b9-4958-439f-a4c9-340180e11e13%40googlegroups.com<https://groups.google.com/d/msgid/google-apps-manager/450d70b9-4958-439f-a4c9-340180e11e13%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
Ross Scroggs
ross.s...@gmail.com

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/CAJkvRS_opcp9Bs7bAwOq749tLVH_6j4ooohsUinxW_Cc_2%3DnWg%40mail.gmail.com<https://groups.google.com/d/msgid/google-apps-manager/CAJkvRS_opcp9Bs7bAwOq749tLVH_6j4ooohsUinxW_Cc_2%3DnWg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
Kevin Melillo
Electronic Communications Analyst
Information Technology
445 Hoes Lane
Piscataway, NJ 08854

Phone:732-465-6609 | Mobile: 732-609-4331
E-mail: k.me...@ieee.org

[https://docs.google.com/uc?export=download&id=0B4tmVQ9eDV8pbGJRUFZxVzdhRTQ&revid=0B4tmVQ9eDV8pb3RwWm5aUERRb2U5bDFMOTY1cCtjREcrZU1NPQ]

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com<mailto:google-apps-man...@googlegroups.com>.
To post to this group, send email to google-ap...@googlegroups.com<http://googlegroups.com/>.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/CAKM%3Dboa5vH%2B%2B9rQxjZnhg0XUw5RzeayN0Gupn0qnEaJjoCCCoQ%40mail.gmail.com<https://groups.google.com/d/msgid/google-apps-manager/CAKM%3Dboa5vH%2B%2B9rQxjZnhg0XUw5RzeayN0Gupn0qnEaJjoCCCoQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
Ross Scroggs
ross.s...@gmail.com<http://gmail.com/>

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com<mailto:google-apps-man...@googlegroups.com>.
To post to this group, send email to google-ap...@googlegroups.com<mailto:google-ap...@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/adc56d52-4da0-4b63-9a36-251930fab465%40googlegroups.com<https://groups.google.com/d/msgid/google-apps-manager/adc56d52-4da0-4b63-9a36-251930fab465%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
Ross Scroggs
ross.s...@gmail.com<mailto:ross.s...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "GAM for G Suite" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-manager/o1BcJ2hP9ac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-man...@googlegroups.com<mailto:google-apps-man...@googlegroups.com>.
To post to this group, send email to google-ap...@googlegroups.com<mailto:google-ap...@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/CAJkvRS8qr45GvMrLFBsFwYCYxRWP4XUCZy50vjWNZiomtbQwRA%40mail.gmail.com<https://groups.google.com/d/msgid/google-apps-manager/CAJkvRS8qr45GvMrLFBsFwYCYxRWP4XUCZy50vjWNZiomtbQwRA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


________________________________

This electronic mail transmission and any files transmitted with it may contain confidential information only for use by the intended recipients. Unless you are the addressee (or authorized to receive messages for the addressee), you may not use, copy, disclose, or distribute this message (or any information contained in or attached to it) to anyone. If you received this communication in error, please notify the sender by reply e-mail and then delete the communication from your electronic mail system.


Ross Scroggs

unread,
May 25, 2018, 8:14:41 PM5/25/18
to google-ap...@googlegroups.com
Menko,

Adding a prefix can be done with Gam 4.40.

gam print users query "orgUnitPath='/Students/School/2018’” | gam csv - gam update user ~primaryEmail email grad_~~primaryEmail~~

~primaryEmail is used as a stand-alone argument
~~primaryEmail~~ can be combined with literals within an argument

Ross


For more options, visit https://groups.google.com/d/optout.


--
Reply all
Reply to author
Forward
0 new messages