Faster way to retrieve multiple passwords at once

Andy2002a
Andy2002a
Community Member
edited June 2020 in CLI

I'm trying to find the easiest/fastest way to retrieve multiple items with a password at once in PowerShell.

Right now I'm doing the following:

  • List all of the items in a vault
    • $All1PassItems += Invoke-Expression "$OnePassAppPath list items --vault $Vault 2>&1" | ConvertFrom-Json (this is fast)
  • Run a loop that retrieves the password for each item
    • $PWitems = Invoke-Expression "$OnePassAppPath get item $($ItemUUID) --fields username,password,notesPlain,title,url" -ErrorAction Stop | ConvertFrom-Json (this in a loop is slow)

This works well and it gives me what I need, but it's super slow because it has to run a query for each individual item. Is there a more efficient way to do this?


1Password Version:1.0
_Extension Version:
Not Provided
OS Version: Not Provided
Sync Type: Not Provided

Comments

  • felix_1p
    felix_1p
    1Password Alumni

    Not yet but there will be "soon" :smile: We are working on better support for pipelining so that e.g. you can pipe a list of items (or item UUIDs) to get item. You will be able to do something like op list items --vault <vault> | op get item - --fields .... So far our tests have shown big performance improvements compared to using a shell loop.

  • Andy2002a
    Andy2002a
    Community Member
    edited June 2020

    Thanks! Is there any way to be notified when it is implemented?

  • felix_1p
    felix_1p
    1Password Alumni

    I'm happy to comment in this thread once it's implemented.

  • felix_1p
    felix_1p
    1Password Alumni

    @Andy2002a We released v1.3.0 today which adds support for standard input to op get item. I hope you like it!

  • Andy2002a
    Andy2002a
    Community Member

    @felix_1p thanks this is way faster now!

    Is it possible to return the UUID of an object when using the --fields parameter?

  • felix_1p
    felix_1p
    1Password Alumni

    @Andy2002a Not yet unfortunately. We haven't decided yet how exactly we want this work. E.g. I could imagine that "internal" fields like UUID would be specified as @uuid instead...
    For now you'd have to use jq but of course that would make selecting the other fields more complicated.
    I'm sorry.

  • Andy2002a
    Andy2002a
    Community Member

    Got it thank you.

  • ag_ana
    ag_ana
    1Password Alumni

    :+1: :)

  • rnot
    rnot
    Community Member
    edited July 2020

    Just came here to say how much I appreciate this new functionality in v1.3.0 of the CLI tool. Being able to get multiple items at once has increased the speed of our automation scripts by about 3x. So much better now, keep up the good work!

    On a side note, I'm partial to using jp instead of jq. jp (jmespath.org) is used in Ansible's built-in json_query filter, and I find that much more easier to build queries than jq.

    EDIT: My 3x remark was the whole script. If you look just at the step where we get items from 1Password, that was reduced from 336 seconds to 45 seconds.

  • Those are incredible results, @rnot. Thanks for sharing, as well as for the suggestion re: jp.

    Ben

This discussion has been closed.