How to find all accounts where a user is in the Manager's Email field

56 views
Skip to first unread message

Raymond Val

unread,
Feb 13, 2025, 4:01:37 PM2/13/25
to GAM for Google Workspace
Hi All,

I am looking for a GAM only way to find all of the accounts where a user is in the Manager's Email field.  

We use the managers email field to designate who is responsible for a service account or an account such as a club / society advisor, Departmental Chair, etc. As part of the account disabling process we would like to identify all of the accounts that a user is responsible for so we can either move them to another user or disable them.

So far the only thing I have been able to come up with is:

gam print users limittoou Dept_accounts fields relations manager | grep <email>

I would really like to remove the "| grep <email>" and use a straight gam command as our disabling process is a script running gam commands. I have tried using various options like csv_output_row_filter or emailmatchpattern but none seem to work.  

Any help or ideas would be greatly appreciated. 

Thank you.

Ray

Ross Scroggs

unread,
Feb 13, 2025, 4:07:47 PM2/13/25
to google-ap...@googlegroups.com
See: https://developers.google.com/admin-sdk/directory/v1/guides/search-users

gam print users query "orgUnitPath='/Dept_accounts' directManager=man...@domain.com"

Ross
----
Ross Scroggs



--
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 visit https://groups.google.com/d/msgid/google-apps-manager/871f77a4-e6ea-4f0e-894d-76b64051363bn%40googlegroups.com.

Raymond Val

unread,
Feb 13, 2025, 4:24:53 PM2/13/25
to GAM for Google Workspace
Thank you very much Ross!

That works very well and it is MUCH quicker then my solution even when searching all of the OUs.

-Ray

Ross Scroggs

unread,
Feb 13, 2025, 4:29:57 PM2/13/25
to google-ap...@googlegroups.com
The orgUnitPath query is for the named OU and sub OUs.
This will search all OUs: gam print users query "orgUnitPath='/' directManager=man...@domain.com"
But at that point just drop the orgUnitPath aout of the query: gam print users query "directManager=man...@domain.com"

Ross
----
Ross Scroggs



Raymond Val

unread,
Feb 13, 2025, 4:51:54 PM2/13/25
to GAM for Google Workspace
Thank you again.  

One follow up question if you don't mind. I am not sure if it is possible though. 
How would I adjust the command so it would only output the account name without the header row.
Using what you provided I am testing: 

    gam redirect stdout ./logfile.csv append print users query "directManager=<user>@sewanee.edu"

I am getting the following in the logfile.csv 
primaryEmail
<user>-te...@sewanee.edu

Is it possible to output just "raval...@sewanee.edu" instead of the header?
I looked at the csv output filtering but that did not seem to do it.

Thank you again!
Ray

Ross Scroggs

unread,
Feb 13, 2025, 5:38:56 PM2/13/25
to google-ap...@googlegroups.com
gam redirect csv ./logfile.csv append noheader print users query "directManager=<user>@sewanee.edu"

Ross
----
Ross Scroggs


Reply all
Reply to author
Forward
0 new messages