Query Users of Multiple Orgs

424 views
Skip to first unread message

Cooldude9210

unread,
Mar 2, 2023, 2:07:42 PM3/2/23
to GAM for Google Workspace
I know I must be missing something small here, but I cannot figure out how to create a .csv of users from multiple ous. 

Here's what I've tried:
  • gam print users email queries "orgUnitPath='/Students/3rd Grade', orgUnitPath='/Students/4th Grade', orgUnitPath='/Students/6th Grade'"

  • gam print users email ous "'/Students/3rd Grade' '/Students/4th Grade' '/Students/6th Grade'"

  • gam print users email limittoous "'/Students/3rd Grade' '/Students/4th Grade' '/Students/6th Grade'"

  • gam print users email queries "'orgUnitPath=/Students/3rd Grade' 'orgUnitPath=/Students/4th Grade' 'orgUnitPath=/Students/6th Grade'"

  • gam print users email queries "orgUnitPath='/Students/3rd Grade' orgUnitPath='/Students/4th Grade' orgUnitPath='/Students/6th Grade'"

  • gam print users email queries "orgUnitPath='/Students/3rd Grade'" "orgUnitPath='/Students/4th Grade'" "orgUnitPath='/Students/6th Grade'"

Every time, the command fails. It either gives an invalid argument, usually centered on the "ous", "limittoous" or something similar, or it can't find any users that match query (orgUnitPath=/Students/3rd Grade).

I've double checked that my OUs' names are correct. Can anyone help me understand what's happening? Thank you!

Kendal White

unread,
Mar 2, 2023, 4:03:55 PM3/2/23
to GAM for Google Workspace
Because the orgUnitPath requires a string type, you will probably have to put the OU names in another variable and run a foreach statement to cycle through the OU's one at a time.

$OUs = "/Students/3rd Grade", "/Students/6th Grade"
foreach ($GOU in $OUs)
{
gam print users email query "orgUnitPath='$GOU'"

Maj Marshall Giguere

unread,
Mar 2, 2023, 6:18:12 PM3/2/23
to google-ap...@googlegroups.com
If you are using advanced gam you can put the ous into a csv file and use the multiprocess option to collect all the output into a single csv file.

file: OUS.csv
ou
"/Students/3rd Grade"
"/Students/4th Grade"
"/Students/6th Grade"

$ gam redirect csv ./EmailActivity.csv multiprocess csv ./OUS.csv gam print users email query "orgUnitPath='~~ou~~'"

Maj Marshall E Giguere

NH Wing Director of IT

Civil Air Patrol, U.S. Air Force Auxiliary

GoCivilAirPatrol.com

nhwg.cap.gov

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/1af354bd-8e1f-47ec-8cdb-f3134527218an%40googlegroups.com.

Maj Marshall Giguere

unread,
Mar 2, 2023, 6:26:06 PM3/2/23
to google-ap...@googlegroups.com
Don't know what I was thinking.  I think it should work as a single process:

$ gam redirect csv ./EmailActivity.csv csv ./OUS.csv gam print users email query "orgUnitPath='~~ou~~'"


Maj Marshall E Giguere

NH Wing Director of IT

Civil Air Patrol, U.S. Air Force Auxiliary

GoCivilAirPatrol.com

nhwg.cap.gov

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


James SEYMOUR

unread,
Mar 2, 2023, 7:31:44 PM3/2/23
to GAM for Google Workspace
Your 5th option should work if you put a comma in between each orgUnitPath. However, this will also check sub-OUs for each of the OUs, so may not be what you need.

gam print users email queries "orgUnitPath='/Students/3rd Grade',orgUnitPath='/Students/4th Grade',orgUnitPath='/Students/6th Grade'"

Kim Nilsson

unread,
Mar 5, 2023, 3:14:19 AM3/5/23
to GAM for Google Workspace
The word email feels unnecessary, as all print users commands will print the email of each user as that is their primary identifier.

James SEYMOUR

unread,
Mar 5, 2023, 7:25:19 PM3/5/23
to GAM for Google Workspace
Hi Kim,

print users returns just the primaryEmail field, whereas print users email returns (for me) primaryEmail,emails,emails.0.address,emails.0.primary,emails.1.address,emails.2.address,emails.3.address

Where emails is a number and I assume the max number of the email addresses returned can be different. 

Cheers

James

Kim Nilsson

unread,
Mar 6, 2023, 1:47:42 AM3/6/23
to google-ap...@googlegroups.com
Yes, but nobody should have more than one relevant email address, and it should be their primary email.--
/Kim
--
There is No Substitute!

James SEYMOUR

unread,
Mar 6, 2023, 6:42:34 PM3/6/23
to GAM for Google Workspace
Hi Kim,

Agreed, users should not have more than one 'active' address, their primary email address. However, we do have a lot of users with aliases. Our MIS creates users in our AD and some Nationalities can have very long names. We then change those that need changing to make the users username easier to type, esp for the younger students.

While we probably never need to use these aliases, they are there if you may need to get a report on them.

Cheers

James

Reply all
Reply to author
Forward
0 new messages