Invoke Powershell LastPass login

Hi, we needed a quicker way to interact with LastPass credentials besides actually logging in and collecting the data, which we tried and had a number of issues and mixed results.

We installed lastpass cli library with cygwin and once everything was in place, ran the necessary commands through Cygwin command prompt, and managed to get a specific account’s saved username and password.

Next we tried it on Powershell and Command Prompt, and besides some minor changes in the prompts/commandlets, they still worked. The below are what we’re using to manually login and request the password from a particular account saved in our lastpass account, so we know they are working manually.

cd cygwin64\bin
.\lpass login lastpass@email.com --trust
[lastpass master pass]
.\lpass show “[lastpass credential name]” --password

Now, in order to use the within an automation, we ended up splitting the above code and testing it in parts. We saved it in .txt files and tested/ran it in parts to see if we can get it to work, and even tested it manually before moving forward.

The parts are the login part first:

[cd ‘C:\cygwin64\bin’
.\lpass login [lastpass@email.com] --trust
[lastpass master password]
]

And the credential request:

[cd ‘C:\cygwin64\bin’
$CurrentPass = .\lpass show “[lastpass credential name]” --password
]

When we open Powershell, and copy paste the above prompts in full, it is working, logging in, then credential fetching.

When we manually login, and then just run a UiPath process using Invoke Powershell command with the password fetching commands, the process is collecting the password and saving it in a variable.

Also, as you can see from the above 2 parts, they are both saved with a [new line]/Enter at the end, as without it, the commands do not work properly, both manually and through UiPath. We are also ticking the IsScript option in the properties, and also tested passing and receiving parameters from the script, which did work for us, as I mentioned the second part did work properly on its own.

Our issue is the login part. When we run that script through the Invoke Powershell activity, we are getting the below error:
Please enter the LastPass master password for [lastpass@email.com].
NotSpecified: (:String) , RemoteException
Master Password: Error: Failed to enter correct password.
The term ‘[lastpass master password]’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Attached is a screenshot from the activity’s properties.
image

After seeing the above error, we tried to pass the password as a paramter. We were trying with the password directly as it worked manually and to try the simplest version first. So we changed the script to the below:

[Param(
[Parameter(Mandatory=$true)]
[string]$Master_Pass
)

cd ‘C:\cygwin64\bin’
.\lpass login [lastpass@email.com] --trust
$Master_Pass
]

Properties for the above:

We’re getting the below error after running the above:
Please enter the LastPass master password for [lastpass@email.com].
NotSpecified: (:String) , RemoteException
Master Password: Error: Failed to enter correct password.

Have you tested with:

cd 'C:\cygwin64\bin'
$env:LPASS_DISABLE_PINENTRY=1
echo $Master_Pass | .\lpass login [lastpass@email.com] --trust

Thanks, but I still get:
Please enter the LastPass master password for [lastpass@email.com].
NotSpecified: (:String) , RemoteException
Master Password: Error: Failed to enter correct password.

I updated the proper email and I even tried reverting back to the hard coded password.

image

Do I maybe have to update the Type Argument in a way? It didn’t seem relevant since I am not getting any output from the script.

I also don’t believe the TypeArgument is relevant here.

It doesn’t seem like the environment flag registered correctly. Could you test with quotes around the 1 value? (Test with both single quotes and double quotes). Also an ampersand might be needed before lpass.

cd 'C:\cygwin64\bin'
$env:LPASS_DISABLE_PINENTRY='1'
echo $Master_Pass | & .\lpass login [lastpass@email.com] --trust

Thanks, but I keep getting the error.

Tried with ’ and " around the 1, both with and without the &

Another thing I didn’t mention that I tried to ask Gemini and it had suggested trying the below command line:

.\lpass login [lastpass@email.com] --password $Master_Pass

But --password is not a property/command associated with .\lpass login, correct?

Yes, that’s correct --password doesn’t exist for lpass login. Gemini is just hallucinating.

Source: Customer

The main issue is that lpass login is prompting for a password. To automate the login we need to get around it somehow. Setting the environment flag and echoing the password with pipeline is what the web says is the solution.

https://manpages.debian.org/unstable/lastpass-cli/lpass.1.en.html#Password_Entry

We checked through another LLM and got this reply:
“The issue you’re encountering stems from how lpass handles password input when automating the login process. Even though you’ve set LPASS_DISABLE_PINENTRY, lpass still reads the password directly from the terminal (/dev/tty), not from stdin. This means that piping the password using echo doesn’t work as expected in this context.”

The script we tried last through Invoke Powershell was:

cd ‘C:\cygwin64\bin’
$env:LPASS_DISABLE_PINENTRY=“1”
echo $Master_Pass | .\lpass login [lastpass@email.com] --trust

Hi, we managed to go around the issue, by creating a sequence dedicated to logging into Lastpass cli, which uses the Use App/Browser activity to physically launch the Powershell application, then it uses send text activities to send the login command and the masterpassword. Once this is done, another sequence takes over which uses the Invoke Powershell activity to run lpass status command, to monitor login status and launch the login sequence if logged out, and lpass show command, to request relevant credentials.

We had tried to use the Use App/Browser before, but we did not have UiPath Studio installed in the environment, so when we tried it, the applications’ instance wasn’t being found.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.