Remove User from All Groups

10,873 views
Skip to first unread message

JRock

unread,
Sep 19, 2012, 1:30:11 PM9/19/12
to google-ap...@googlegroups.com
I can understand the thought process, but am unfamiliar with scripting. Has anyone wrote a script for removing a user from all groups?

I'd assume you would list the users info to get the group memberships, parse it, then pipe that date into a list/index and run a remove from group on that list for that user.

Hoping that I could just type in the username and then it would just remove all groups.

Dave Bailey

unread,
Sep 19, 2012, 1:38:31 PM9/19/12
to google-ap...@googlegroups.com
I have a very rough powershell script to either clone a users groups to another user or purge a user from all groups.  If you want a copy I can send it as a txt file.

Thanks/Dave

--
You received this message because you are subscribed to the "Google Apps Manager" group.
To post to this group, send email to
google-ap...@googlegroups.com
To unsubscribe from this group, send email to
google-apps-man...@googlegroups.com
For more options, visit this group at
https://groups.google.com/forum/#!forum/google-apps-manager



--


David Bailey
Multnomah County 
Google BSA
General Government/Open Source

JRock

unread,
Sep 19, 2012, 1:42:44 PM9/19/12
to google-ap...@googlegroups.com
That would be greatly appreciated. I think if I had a ground work I could likely adapt it to the specific needs.


On Wednesday, September 19, 2012 10:38:53 AM UTC-7, David Bailey wrote:
I have a very rough powershell script to either clone a users groups to another user or purge a user from all groups.  If you want a copy I can send it as a txt file.

Thanks/Dave

On Wed, Sep 19, 2012 at 10:30 AM, JRock <jamie...@tapjoy.com> wrote:
I can understand the thought process, but am unfamiliar with scripting. Has anyone wrote a script for removing a user from all groups?

I'd assume you would list the users info to get the group memberships, parse it, then pipe that date into a list/index and run a remove from group on that list for that user.

Hoping that I could just type in the username and then it would just remove all groups.

--
You received this message because you are subscribed to the "Google Apps Manager" group.
To post to this group, send email to
google-ap...@googlegroups.com
To unsubscribe from this group, send email to

For more options, visit this group at
https://groups.google.com/forum/#!forum/google-apps-manager

JP Connolly

unread,
Sep 19, 2012, 1:52:59 PM9/19/12
to google-ap...@googlegroups.com
I'd love to take a look as well please!


For more options, visit this group at
https://groups.google.com/forum/#!forum/google-apps-manager



--
JP Connolly
Director of Technology
Saint Ann's School
129 Pierrepont St.
Brooklyn, NY 11201

Dave Bailey

unread,
Sep 19, 2012, 2:00:59 PM9/19/12
to google-ap...@googlegroups.com
For all who enjoy hacked together powershell scripts, I present, groupsetV0.

Thanks/Dave 
groupsetV0.1.txt

JRock

unread,
Sep 19, 2012, 2:30:25 PM9/19/12
to google-ap...@googlegroups.com
Quick question for those more handy with powershell than I;

This was my attempt on a pre-parsing script in the last few minutes before posting here, never ran it, but it made sense....
There would be a CSV file which all the groups would be pasted into col 2, and a single username pasted into col 1 both would be identified by top row "username",  "groups" accordingly.

I guess the part I stumbled on was see if the foreach and $list would work with only running through a single column when you import a CSV. Hence the $entry.groups in $list

Would this have worked?

$list = Import-Csv rmgroups.csv
foreach ($entry.groups in $list)
  {
    .\gam.exe update group $($entry.groups) remove owner $($entry.username)
    .\gam.exe update group $($entry.groups) remove member $($entry.username)

  }

On Wednesday, September 19, 2012 11:01:22 AM UTC-7, David Bailey wrote:
For all who enjoy hacked together powershell scripts, I present, groupsetV0.

Thanks/Dave 

On Wed, Sep 19, 2012 at 10:52 AM, JP Connolly <jpcon...@saintannsny.org> wrote:
I'd love to take a look as well please!
On Wed, Sep 19, 2012 at 1:42 PM, JRock <jamie...@tapjoy.com> wrote:
That would be greatly appreciated. I think if I had a ground work I could likely adapt it to the specific needs.


On Wednesday, September 19, 2012 10:38:53 AM UTC-7, David Bailey wrote:
I have a very rough powershell script to either clone a users groups to another user or purge a user from all groups.  If you want a copy I can send it as a txt file.

Thanks/Dave

On Wed, Sep 19, 2012 at 10:30 AM, JRock <jamie...@tapjoy.com> wrote:
I can understand the thought process, but am unfamiliar with scripting. Has anyone wrote a script for removing a user from all groups?

I'd assume you would list the users info to get the group memberships, parse it, then pipe that date into a list/index and run a remove from group on that list for that user.

Hoping that I could just type in the username and then it would just remove all groups.

--
You received this message because you are subscribed to the "Google Apps Manager" group.
To post to this group, send email to
google-ap...@googlegroups.com

To unsubscribe from this group, send email to

For more options, visit this group at
https://groups.google.com/forum/#!forum/google-apps-manager



--


David Bailey
Multnomah County 
Google BSA
General Government/Open Source

--
You received this message because you are subscribed to the "Google Apps Manager" group.
To post to this group, send email to
google-ap...@googlegroups.com
To unsubscribe from this group, send email to
google-apps-manager+unsub...@googlegroups.com
For more options, visit this group at
https://groups.google.com/forum/#!forum/google-apps-manager



--
JP Connolly
Director of Technology
Saint Ann's School
129 Pierrepont St.
Brooklyn, NY 11201

--
You received this message because you are subscribed to the "Google Apps Manager" group.
To post to this group, send email to
google-ap...@googlegroups.com
To unsubscribe from this group, send email to

Dan Seward

unread,
Dec 17, 2013, 9:05:49 AM12/17/13
to google-ap...@googlegroups.com
I appreciate your ps script but the group members and the individual group memberships from Google can't be trusted, especially after making several updates. Google will update the groups but the member lists from GAM and the Admin Console are not always updated right away. This could take hours and in some cases days. 

I opened a ticket with Google because of a problem verifying group memberships after running GADS. I was told there is an "Admin console propagation delay" that caused the user accounts to not appear in the list correctly. In most cases this issue is benign as mail will still be delivered to the user through this group, but if you're using GAM to show you what groups an particular person is a member of, it may not be correct.

This may not be a problem for corporations but we are a University and update our student groups daily. Some days when there are 1,000's of adds or deletes, we have to use our Active Directory groups that we sync from because the Admin Console and GAM are not correct.

Roman T

unread,
Apr 7, 2015, 4:35:00 PM4/7/15
to google-ap...@googlegroups.com
Attached is a simple bash script which removes user from all groups.
google-remove-user-from-all-groups.sh

Ross Scroggs

unread,
Apr 8, 2015, 11:05:18 PM4/8/15
to google-ap...@googlegroups.com
A script written by a true sed master; however, gam can do this directly. I can’t find this specifc command in the Wiki but it’s in the code.

Syntax: gam user <username>|group <groupname>|ou <ouname>|all users delete groups
Example: gam user f...@bar.com delete groups

"user <username>|group <groupname>|ou <ouname>|all users generates a list of users, maybe all of the users you have; use with extreme caution!
--
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/27fb8572-1174-4af6-bc40-6efaa8897401%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<google-remove-user-from-all-groups.sh>

Marion Bates

unread,
Aug 30, 2015, 2:35:17 PM8/30/15
to Google Apps Manager
THANK YOU ROSS! Been wishing for this for years, and tried to roll my own sed/awk cuteness, but just not quite l33t enough. 

-- MB


On Wednesday, April 8, 2015 at 11:05:18 PM UTC-4, Ross Scroggs wrote:
A script written by a true sed master; however, gam can do this directly. I can’t find this specifc command in the Wiki but it’s in the code.

Syntax: gam user <username>|group <groupname>|ou <ouname>|all users delete groups
Example: gam user f...@bar.com delete groups

"user <username>|group <groupname>|ou <ouname>|all users generates a list of users, maybe all of the users you have; use with extreme caution!
On Apr 7, 2015, at 1:34 PM, Roman T <rom...@gmail.com> wrote:

Attached is a simple bash script which removes user from all groups.

On Wednesday, September 19, 2012 at 1:30:11 PM UTC-4, JRock wrote:
I can understand the thought process, but am unfamiliar with scripting. Has anyone wrote a script for removing a user from all groups?

I'd assume you would list the users info to get the group memberships, parse it, then pipe that date into a list/index and run a remove from group on that list for that user.

Hoping that I could just type in the username and then it would just remove all groups.

--
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.

Tiago Tavares

unread,
Oct 9, 2015, 3:16:47 PM10/9/15
to Google Apps Manager
Hi Ross,

I'm trying to delete an email address from all the groups. The output of using your command is "f...@bar.com is in 0 groups".
But it actually is in many different groups.

Any thoughts on how I can delete an email address that is not part of the domain from the groups?

Thanks!


On Thursday, April 9, 2015 at 4:05:18 AM UTC+1, Ross Scroggs wrote:
A script written by a true sed master; however, gam can do this directly. I can’t find this specifc command in the Wiki but it’s in the code.

Syntax: gam user <username>|group <groupname>|ou <ouname>|all users delete groups
Example: gam user f...@bar.com delete groups

"user <username>|group <groupname>|ou <ouname>|all users generates a list of users, maybe all of the users you have; use with extreme caution!
On Apr 7, 2015, at 1:34 PM, Roman T <rom...@gmail.com> wrote:

Attached is a simple bash script which removes user from all groups.

On Wednesday, September 19, 2012 at 1:30:11 PM UTC-4, JRock wrote:
I can understand the thought process, but am unfamiliar with scripting. Has anyone wrote a script for removing a user from all groups?

I'd assume you would list the users info to get the group memberships, parse it, then pipe that date into a list/index and run a remove from group on that list for that user.

Hoping that I could just type in the username and then it would just remove all groups.

--
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.
To post to this group, send email to google-apps-manager@googlegroups.com.

Jay Lee

unread,
Oct 9, 2015, 3:22:41 PM10/9/15
to Google Apps Manager

There's no API call to get all groups a non-domain user is in so at best you'd run:

gam print groups | gam csv - gam update group ~Email delete extern...@domain.com

Which will try to remove the user from every single group. It'll take a long time and throw a lot of errors but should get the job done.

Jay


On Fri, Oct 9, 2015, 3:16 PM Tiago Tavares <admini...@colegioescravas.net> wrote:
Hi Ross,

I'm trying to delete an email address from all the groups. The output of using your command is "f...@bar.com is in 0 groups".
But it actually is in many different groups.

Any thoughts on how I can delete an email address that is not part of the domain from the groups?

Thanks!


On Thursday, April 9, 2015 at 4:05:18 AM UTC+1, Ross Scroggs wrote:
A script written by a true sed master; however, gam can do this directly. I can’t find this specifc command in the Wiki but it’s in the code.

Syntax: gam user <username>|group <groupname>|ou <ouname>|all users delete groups
Example: gam user f...@bar.com delete groups

"user <username>|group <groupname>|ou <ouname>|all users generates a list of users, maybe all of the users you have; use with extreme caution!
On Apr 7, 2015, at 1:34 PM, Roman T <rom...@gmail.com> wrote:

Attached is a simple bash script which removes user from all groups.

On Wednesday, September 19, 2012 at 1:30:11 PM UTC-4, JRock wrote:
I can understand the thought process, but am unfamiliar with scripting. Has anyone wrote a script for removing a user from all groups?

I'd assume you would list the users info to get the group memberships, parse it, then pipe that date into a list/index and run a remove from group on that list for that user.

Hoping that I could just type in the username and then it would just remove all groups.

--
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/27fb8572-1174-4af6-bc40-6efaa8897401%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<google-remove-user-from-all-groups.sh>

--
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.

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

Jay Lee

Tiago Tavares

unread,
Oct 9, 2015, 3:31:59 PM10/9/15
to Google Apps Manager
So, I'm kind of new with GAM. Let me see if I got that right:
gam print groups
gam csv
gam update group email delete exte...@domain.com

?
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@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/27fb8572-1174-4af6-bc40-6efaa8897401%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<google-remove-user-from-all-groups.sh>

--
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.
--

Jay Lee

Graham Ingleby

unread,
Oct 12, 2015, 4:14:33 AM10/12/15
to GAM group
It's one long command, so your output from print groups is the CSV file you use for the Update Group part

gam print groups | gam csv - gam update group ~Email delete extern...@domain.com

 

 Graham Ingleby | Cloud Computing Consultant | +44 1344 203395 | ging...@ancoris.com
Google+  

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/27fb8572-1174-4af6-bc40-6efaa8897401%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<google-remove-user-from-all-groups.sh>

--
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.
--

Jay Lee

--
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.

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



This message is for the named person's use only. If you receive this message in error, please delete it and notify the sender. Ancoris reserves the right to monitor all e-mail communications through its networks. Ancoris Limited, Registered in England Number: 04830784, Registered address: 5a Frascati Way, Maidenhead, Berkshire SL6 4UY. Trading Address: Lily Hill House, Lily Hill Road, Bracknell, Berkshire RG12 2SJ




Juan Pablo Gomez Espinosa

unread,
Dec 12, 2015, 5:09:10 PM12/12/15
to Google Apps Manager
Found this post thought I would update it and post this great script that I found for GAM.  Many Kudos to the author.


It has the group removal feature and other bonus features.  

Enjoy and thank you for the original post.

On Wednesday, September 19, 2012 at 1:30:11 PM UTC-4, JRock wrote:

Moshe Ben Ezra

unread,
Mar 2, 2016, 9:04:53 AM3/2/16
to Google Apps Manager
Hi, how are you?

The following PS script intended for removing user from all DL groups:


$username = read-host "Enter username account: "
Write-Host "==============Removing $user...@domain.com from all groups=============" -ForegroundColor Cyan
$purge = .\gam.exe info user $user...@domain.com
$purge_chunk = $purge | Select-String "Groups:" -context 0,100
$purge_grps = $purge_chunk.tostring().split(")")
foreach ($line in $purge_grps)
{
$grpaddresspurge = $line.tostring().split("<")[-1].Trim(">")
    if ($grpaddresspurge.contains("(direct member")) 
    {  
    $purgegrp = $grpaddresspurge.replace("> (direct member","") 
    #Write-Host "$purgegrp"
    .\gam.exe update group $purgegrp remove owner $user...@domain.com
    .\gam.exe update group $purgegrp remove member $user...@domain.com
    }
}


unfortunately the script is not updating nothing... can someone advise please?


Moshico.

Ross Scroggs

unread,
Mar 2, 2016, 10:19:47 AM3/2/16
to google-ap...@googlegroups.com
No script is required, there is a gam command to do this: gam user f...@domain.com delete groups

--
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.

a...@iijt.net

unread,
Mar 2, 2016, 11:30:23 PM3/2/16
to google-ap...@googlegroups.com

HI Roos,

 

Thanks a lot, working fine, we have asked the same many times…

 

Now it will save our time lot…… Thanks.

 

Regards,

Lakshmanan

9384712676


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

Please follow the attached hyperlink to an important disclaimer


Please follow the attached hyperlink to an important disclaimer

Moshe Ben Ezra

unread,
Mar 15, 2016, 8:48:40 AM3/15/16
to Google Apps Manager
thank you very much!

:-)
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages