Skip to main content
Jan 26, 2022 9:52 AM UTC
Question

List all Guest Users

Hi Support,

I am trying to list:
1. all Guest users
2. All Active Users
3. All Users
4. All Guest Users and Vaults that they have access to

All Active Users:
op list users | jq -c '.[] | select(.state | contains("A"))'
jq: error: A/0 is not defined at , line 1:
.[] | select(.state | contains(A))
jq: 1 compile error

All Guest Users:
op list users | jq -c '.[] | select(.type | contains("R"))'
jq: error: R/0 is not defined at , line 1:
.[] | select(.type | contains(R))
jq: 1 compile error


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided

6 replies

Feb 7, 2022 10:42 PM UTC

Hey @PeterCharleston ,

The jq commands you are using where the state's value is wrapped in double quotes (eg. contains("A")) looks good to me, I tried it on my machine and it works as well.

Would you be able to validate the output of the op list users command to ensure that it's a properly formatted JSON object?

Feb 8, 2022 8:09 AM UTC

Hi Justin

Which version of CLI and jq are you using?

the command produce arrays in Powershell 5.1

$opsUsersState = op list users | jq -c '.[] | select(.state)'
PS C:\Users\PeterCharleston> $opsUsersState.GetType()

IsPublic IsSerial Name BaseType


True True Object[] System.Array

$opsUserList = op list users | jq -c '.[]'
PS C:\Users\PeterCharleston> $opsUSerList.GetType()

IsPublic IsSerial Name BaseType


True True Object[] System.Array

I can get specific values like email:

$listOfEmails = $(op list users | jq -r '.[] | .email')
PS C:\Users\PeterCharleston> $listOfEmails.GetType()

IsPublic IsSerial Name BaseType


True True Object[] System.Array

Feb 10, 2022 7:53 AM UTC

Hi Justin

Which version of CLI and jq are you using?

the command produce arrays in Powershell 5.1

$opsUsersState = op list users | jq -c '.[] | select(.state)'
PS C:\Users\PeterCharleston> $opsUsersState.GetType()

IsPublic IsSerial Name BaseType


True True Object[] System.Array

$opsUserList = op list users | jq -c '.[]'
PS C:\Users\PeterCharleston> $opsUSerList.GetType()

IsPublic IsSerial Name BaseType


True True Object[] System.Array

I can get specific values like email:

$listOfEmails = $(op list users | jq -r '.[] | .email')
PS C:\Users\PeterCharleston> $listOfEmails.GetType()

IsPublic IsSerial Name BaseType


True True Object[] System.Array

Feb 10, 2022 9:30 PM UTC

Hey @PeterCharleston

Here are the commands that you can use to get the following results:
- get all Guest users

op list users | jq -c '.[] | select(.type == \"G\")'

  • get all Active users

    op list users | jq -c '.[] | select(.state == \"A\")'

  • get all users

    op list users | jq -c '.[]'

  • get all Guest users and the vaults they have access to

    \> $users = (op list users | jq -r '.[] | select(.type == \"G\").email')
    \> foreach ($u in $users) {op list vaults --user $u}

The trick is to escape the quotation marks in the command. For example, "G" becomes \"G\". This discrepancy is present in Powershell.

Feb 11, 2022 7:42 AM UTC

Hey Eddy

that is awesome thanks

I was trying to escape with ` before but not working.

I had written a horrible script which got the job done but this is tons better

regards
Peter

Feb 11, 2022 12:03 PM UTC

Glad to hear that it worked out! :smile: