List all Guest Users

PeterCharleston
PeterCharleston
Community Member

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

Comments

  • 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?

  • PeterCharleston
    PeterCharleston
    Community Member

    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

  • PeterCharleston
    PeterCharleston
    Community Member

    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

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

  • PeterCharleston
    PeterCharleston
    Community Member

    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

  • Glad to hear that it worked out! :smile:

This discussion has been closed.