User Query with Multiple Values

1,865 views
Skip to first unread message

Jeffrey Wickersty

unread,
Oct 28, 2021, 10:49:45 AM10/28/21
to GAM for Google Workspace

Hi everyone,

Been struggling with this for a couple days and thought I'd ask the community if anyone knows anything:

I'm trying to conduct a "gam print users" query with more than one argument in the query, AND with one of the arguments having two possible values. Here's an example of what I've got:

gam print users query "orgName=Engineering (givenName:'Jeffrey' givenName:'Vanessa')" fields id,suspended,ou,primaryEmail,name custom all orderby email

My hope was that this would return all users in the "Engineering" orgName that have a first name that begins with EITHER "Jeffrey" or "Vanessa" but it doesnt seem to work. I've tried various syntaxes for the OR part, including:

  • gam print users query "orgName=Engineering (givenName:'Jeffrey' givenName:'Vanessa')" fields id,suspended,ou,primaryEmail,name custom all orderby email
  • gam print users query "orgName=Engineering {givenName:'Jeffrey' givenName:'Vanessa'}" fields id,suspended,ou,primaryEmail,name custom all orderby email
  • gam print users query "orgName=Engineering (givenName:'Jeffrey'  OR givenName:'Vanessa')" fields id,suspended,ou,primaryEmail,name custom all orderby email
  • gam print users query "orgName=Engineering {givenName:'Jeffrey'  OR givenName:'Vanessa'}" fields id,suspended,ou,primaryEmail,name custom all orderby email
What am I missing? Is it not possible to have a query argument with multiple values (an "OR")?

For reference, the following commands works fine, but only involves one giveName in the query:

gam print users query "isSuspended=FALSE givenName:'Vanessa'" fields id,suspended,ou,primaryEmail,name custom all orderby email

Thanks for your time!

Jeff


Ross Scroggs

unread,
Oct 28, 2021, 11:06:20 AM10/28/21
to google-ap...@googlegroups.com
Jeff,


What do you mean by "all users in the "Engineering" orgName"?
Do you mean an OU named Engineering?
If so the query should be: 
  • gam print users query "orgUnitPath='/Engineering' (givenName:'Jeffrey'  OR givenName:'Vanessa')" fields id,suspended,ou,primaryEmail,name custom all orderby email

Ross

--
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/f3d6d359-84ff-4741-969f-9edfef664667n%40googlegroups.com.


--

Jeffrey Wickersty

unread,
Oct 28, 2021, 11:10:09 AM10/28/21
to GAM for Google Workspace
It's not the org part thats the problem. that could be anything (like, for example, 
  • gam print users query "isSuspended=FALSE' (givenName:'Jeffrey'  OR givenName:'Vanessa')" fields id,suspended,ou,primaryEmail,name custom all orderby email
It's the multi-value second argument OR thats not working. Some other examples, more 'real' to what I'm doing, is:
  • gam print users query "isSuspended=FALSE' (MyCustomSchema.UserClass='CWK-C'  OR MyCustomSchema.UserClass='CWK - C')" fields id,suspended,ou,primaryEmail,name custom all orderby email
  • gam print users query "isSuspended=FALSE' (MyCustomSchema.UserClass='CWK - V'  OR MyCustomSchema.UserClass='CWK - I')" fields id,suspended,ou,primaryEmail,name custom all orderby email
Thanks Ross!

Jeffrey Wickersty

unread,
Oct 28, 2021, 11:13:59 AM10/28/21
to GAM for Google Workspace
Another example:

  • gam print users query "isSuspended=FALSE (ActiveDirectory.Class='FT' ActiveDirectory.Class='FT Employee')" fields id,suspended,ou,primaryEmail,name custom all orderby email


Ross Scroggs

unread,
Oct 28, 2021, 11:57:05 AM10/28/21
to google-ap...@googlegroups.com
Jeff,


gam config csv_output_row_filter "name.givenName:regex:Jeffrey|Vanessa" print users query "orgUnitPath='/Engineering'" fields id,suspended,ou,primaryEmail,name custom all orderby email

Ross



--

Ross Scroggs

unread,
Oct 28, 2021, 12:06:51 PM10/28/21
to google-ap...@googlegroups.com
Jeff,

gam config csv_output_row_filter "customSchemas.ActiveDirectory.Class:regex:^(FT)|(FT Employee)$" print users query "isSuspended=FALSE" fields id,suspended,ou,primaryEmail,name custom all orderby email

Ross



--
Message has been deleted

Chris River

unread,
Oct 29, 2021, 12:12:35 PM10/29/21
to GAM for Google Workspace
The Google API endpoint doesn't support the "OR" statement, it only supports "AND". Ross's way is better as it's more flexible and the API endpoint is very limited in the search parameters it supports. However, if you do want to use the API for this, such as if you don't want to wait for gam to page through all users in a large domain, you can mimic the OR by breaking apart the command into multiple commands:
gam select redirect csv ./test.csv print users query "issuspended=FALSE givenName:'Jeffrey'" fields id,suspended,ou,primaryEmail,name custom all orderby email
gam select redirect csv ./test.csv append noheader print users query "issuspended=FALSE givenName:'Vanessa'" fields id,suspended,ou,primaryEmail,name custom all orderby email

Since these searches are relatively simple, you can improve performance further by placing the OR'd search values in a csv file and multi-processing them:
gam select  redirect csv - multiprocess csv ./names.csv gam print users query "issuspended=FALSE givenName:'~~name~~'" fields id,suspended,ou,primaryEmail,name custom all orderby email

The final sort won't be how you want (each group of search results will be, but not the final output), so if you need it sorted you'll have to sort it after.
Reply all
Reply to author
Forward
0 new messages