Using GAM to modify bulk user accounts without using csv or txt files.

831 views
Skip to first unread message

Muhammad Nabil Isma

unread,
Jan 18, 2015, 7:39:17 AM1/18/15
to google-ap...@googlegroups.com
Good day to all,

I am new to GAM and not much of an expert with scripts. What I want to do is to modify our google users email accounts. The naming structure we are using currently is a letter followed by a group of digits, e.g. 'x12...@mydomain.com'. I need to change this email to remove the letter and leave just the digits, e.g. '12...@mydomain.com'.

What is the best way for me to achieve this, and can I achieve this without using csv or text files, may be by just using a script. Please correct me if I am wrong, but the way I understand it if I use a csv or txt file I will have to list out all the users I want to modify in the file.

Thanks in advance for the assistance.

Steve Carrington

unread,
Jan 18, 2015, 10:23:12 AM1/18/15
to google-ap...@googlegroups.com
Since this would be a one time change, I would recommend pulling all the account info with something like:
gam print users users.txt

Then I would take that file and clean it up and edit in in a spreadsheet to get commands like:
gam update user x12...@mydomain.com username 12...@mydomain.com

using standard spreadsheet tools you can pull all the alpha characters off the emails - insert the actual commands, and get the data into a file that you can then execute in a bat file


--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" 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 http://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/d70f5c10-3334-49ae-b10e-72e310f0a454%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve Carrington
Chief Information Officer
Murphysboro CUSD #186
McElvain School
593 Ava Road
Murphysboro, IL  62966
V - 618-684-3781 X 6108
F - 618-684-2465

"We can't solve problems by using the same kind of thinking we used when we created them."  - Albert Einstein

THIS TRANSMISSION IS INTENDED AND RESTRICTED FOR USE BY THE ABOVE ADDRESSEE ONLY.  IT MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION EXEMPT FROM DISCLOSURE  UNDER FEDERAL OR STATE LAW. IN THE EVENT SOME OTHER PERSON OR ENTITY RECEIVES THIS  TRANSMISSION, SAID RECIPIENT IS HEREBY NOTIFIED THAT ANY DISSEMINATION, DISTRIBUTION,  OR DUPLICATION OF THIS TRANSMISSION OR ITS CONTENTS IS PROHIBITED. IF YOU SHOULD RECEIVE  THIS TRANSMISSION IN ERROR, PLEASE CALL US IMMEDIATELY AT 618-684-3781, DELETE THE FILE FROM YOUR SYSTEM, AND DESTROY ANY HARD COPIES OF THIS TRANSMISSION. THANK YOU.

Murphysboro Community Unit School District #186
Murphysboro, Illinois

Fajar Suryawan

unread,
Jan 18, 2015, 5:47:53 PM1/18/15
to google-ap...@googlegroups.com
Another way is to do it with Python, possibly with its regex capability. Why Python? It's simple yet powerful, and GAM is built with it. I've done several tasks similar to yours by using GAM's Python source code.

Salam.

Muhammad Nabil Isma

unread,
Jan 19, 2015, 1:07:18 AM1/19/15
to google-ap...@googlegroups.com
Thanks Steve, I have downloaded all our users in csv format and I will clean up the file and try what you suggested. However, I will look into Fajar's solution in the mean time. If anything else crosses your mind, please let me know. Thanks again for the assistance.


On Sunday, January 18, 2015 at 7:23:12 PM UTC+4, Steve Carrington wrote:
Since this would be a one time change, I would recommend pulling all the account info with something like:
gam print users users.txt

Then I would take that file and clean it up and edit in in a spreadsheet to get commands like:
gam update user x12...@mydomain.com username 12...@mydomain.com

using standard spreadsheet tools you can pull all the alpha characters off the emails - insert the actual commands, and get the data into a file that you can then execute in a bat file

On Sun, Jan 18, 2015 at 6:39 AM, Muhammad Nabil Isma <mna...@ud.ac.ae> wrote:
Good day to all,

I am new to GAM and not much of an expert with scripts. What I want to do is to modify our google users email accounts. The naming structure we are using currently is a letter followed by a group of digits, e.g. 'x12...@mydomain.com'. I need to change this email to remove the letter and leave just the digits, e.g. '12...@mydomain.com'.

What is the best way for me to achieve this, and can I achieve this without using csv or text files, may be by just using a script. Please correct me if I am wrong, but the way I understand it if I use a csv or txt file I will have to list out all the users I want to modify in the file.

Thanks in advance for the assistance.

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



--
Steve Carrington
Chief Information Officer
Murphysboro CUSD #186
McElvain School
593 Ava Road
Murphysboro, IL  62966
V - 618-684-3781 X 6108
F - 618-684-2465

"We can't solve problems by using the same kind of thinking we used when we created them."  - Albert Einstein

Muhammad Nabil Isma

unread,
Jan 19, 2015, 1:12:05 AM1/19/15
to google-ap...@googlegroups.com
Salaam Fajar, I am not really knowledgeable in python, so if you could share the Python code or script I can use it and guide me on how to use it this would be wonderful. Thanks again in advance and I do apologize if I seem to be asking too much.

+KimNilsson

unread,
Jan 21, 2015, 10:43:44 AM1/21/15
to google-ap...@googlegroups.com
This could probably also be done in a single piped command, but that would instead require you to know commands like sed, awk, cut, and maybe many more to accomplish what you want. Perhaps this is a good place to start. http://mindspill.net/computing/linux-notes/text-manipulation-cut-awk-and-sed/

Still, I think it might be easier to get all your users' information into a spreadsheet first. So you can select only the column of your usernames and run your magic edits on only that data. I guarantee that will be a lot easier.

Also, I wonder if Steve's suggested command line is correct?
According to the wiki this is the complete syntax for user edits.

gam update user <email address>
 [firstname <First Name>] [lastname <Last Name>]
 [password <Password>] [email <New Email>]
 [gal on|off] [admin on|off] [suspended on|off]
 [sha] [md5] [crypt] [nohash]
 [changepassword on|off] [org <Org Name>]

Which would make your command something like this:

gam update user <email address> email <New Email>

But, then again, the wiki example uses "username" and not "email".

To make it pull the info from a CSV, the file would need to contain at least two values: the old username and the new username. Domain name isn't necessary.
Something like this:

gam csv update_users.csv | gam update user ~Email username ~NewUsername

Where update_users.csv is the name of your CSV file and Email and NewUsername are the two relevant headers of the spreadsheet where you have the info.

Muhammad Nabil Isma

unread,
Jan 22, 2015, 2:18:31 AM1/22/15
to google-ap...@googlegroups.com
Thank you all for your help, I was able to do it easily with Kim's method. Thanks again and highly appreciated.
Reply all
Reply to author
Forward
0 new messages