I am writing a script for setting up a vault for automation. The initial run of the script and setup of the new vault runs well. I then tested doing Reset-SecretStore to see what would happen if someone wanted to start again if they didn't know the passwords. This of course resets everything to defaults and I then ran 'Set-SecretStoreConfiguration -Authentication 'Password' -PasswordTimeout 3600 -Interaction 'None' -Confirm:$false' to have a longer timeout and to not prompt. As this command appears to reset the password cached by Unlock-SecretStore, I ran it again immediately after to have it available for the rest of the script. The next part begins with Get-SecretInfo to discover if any users are in the vault, so they can be added if needed.
This results in the following error:
Get-Secretinfo : A valid password is required to access the Microsoft.PowerShell.SecretStore vault.
Use the Unlock-SecretStore cmdlet to provide the required password to access the store.
I have attempted to put Unlock-SecretStore in different places in the script and even went to far as to run it before every command to get it to function as expected. There seems to be always a part where it randomly fails to supply the necessary password for the vault.
Expected behavior
Once Unlock-SecretStore is run, the password is cached and available to other commands being run by the script
Actual behavior
Random failure with an error to 'Use the Unlock-SecretStore cmdlet to provide the required password to access the store.'
Error details
Get-Secretinfo : A valid password is required to access the Microsoft.PowerShell.SecretStore vault.
Use the Unlock-SecretStore cmdlet to provide the required password to access the store.
At C:\GitLab\hpe-oneview-and-ilo-provisioning\HPiLO-Import.ps1:183 char:18
+ ... $accounts = (Get-Secretinfo -Vault VenafiPS -ErrorAction Stop).Name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Power...cretInfoCommand:GetSecretInfoCommand) [Get-SecretInfo], PasswordRequiredException
+ FullyQualifiedErrorId : GetSecretInfoException,Microsoft.PowerShell.SecretManagement.GetSecretInfoCommand
Prerequisites
Steps to reproduce
I am writing a script for setting up a vault for automation. The initial run of the script and setup of the new vault runs well. I then tested doing Reset-SecretStore to see what would happen if someone wanted to start again if they didn't know the passwords. This of course resets everything to defaults and I then ran 'Set-SecretStoreConfiguration -Authentication 'Password' -PasswordTimeout 3600 -Interaction 'None' -Confirm:$false' to have a longer timeout and to not prompt. As this command appears to reset the password cached by Unlock-SecretStore, I ran it again immediately after to have it available for the rest of the script. The next part begins with Get-SecretInfo to discover if any users are in the vault, so they can be added if needed. This results in the following error: Get-Secretinfo : A valid password is required to access the Microsoft.PowerShell.SecretStore vault. Use the Unlock-SecretStore cmdlet to provide the required password to access the store.
I have attempted to put Unlock-SecretStore in different places in the script and even went to far as to run it before every command to get it to function as expected. There seems to be always a part where it randomly fails to supply the necessary password for the vault.
Expected behavior
Actual behavior
Error details
Environment data
Version
Using VS Code on Windows 10
Visuals
No response