Forum Discussion

Anonymous's avatar
Anonymous
3 years ago

"error initializing client" with multiple CLI calls

I've written a PowerShell script to grab credentials from 1Password for authenticating with a service. The script has been working great for months, but recently started throwing errors. I think I've isolated it to some sort of race condition.

Here's the simplest version of the script that consistently replicates the issue with some minor redactions:
```
$1p_item = '[ITEM UID - REDACTED]'
$1p_cli_exe = 'C:\some\path\here\op.exe'

Write-Output "Grabbing login info from 1Password..."

Write-Output "Username:"
$1p_item_username = & "$1p_cli_exe" read op://myVault/$1p_item/username
Write-Output $1p_item_username

Write-Output "Password:"
$1p_item_password = & "$1p_cli_exe" read op://myVault/$1p_item/password
Write-Output $1p_item_password

Write-Output "Done"
Start-Sleep -Seconds 60
```

Output:

Grabbing login info from 1Password...
Username:
[MY USERNAME - REDACTED]
Password:
[ERROR] 2023/04/03 12:48:39 could not read secret op://myVault/[ITEM UID - REDACTED]/password: error initializing client: connecting to desktop app: cannot connect to 1Password app, make sure it is running
Done

I'm getting prompted to authenticate via Windows Hello and you can see it's successfully grabbing the username, so the error doesn't make any sense to me. Annoyingly, it's inconsistent, but does seem to get worse as more calls to read info from 1Password are made.

It could be changes to PowerShell or something in the Windows 11 22H2 update, but I haven't managed to find anything.

Has anyone else encountered this? I'm open to suggestions on how to restructure the script if there's a better way to accomplish the same thing.

I would use the CLI inject option instead, but I need an OTP (not included in the code sample above). Also worth noting, I'm unable to alter my machine's PATH variable, which is why I'm calling the executable with a hard coded path.


1Password Version: 1Password for Windows 8.10.3 (81003012)
Extension Version: CLI v. 2.16.1
OS Version: Windows 11 22H2
Browser:_ N/A

8 Replies

No Replies