PowerShell / SecretStore

MIT License
158 stars 24 forks source link

Cannot use Set-SecretStorePassword with parameter arguments to set a new password, without an existing password #94

Closed Kaiyiccc closed 1 year ago

Kaiyiccc commented 2 years ago

I'm trying to set a new password for SecretStore using parameter arguments rather than interactively.

Based on what's written in the documentation, something like this should work when no password have been previously set:

Set-SecretStorePassword -NewPassword $newPassword

However I'm getting this error and cannot leave the -Password argument blank, no matter my input type:

PS C:\Users\k> Set-SecretStorePassword -NewPassword $MyCredential.Password
Set-SecretStorePassword : Cannot bind parameter 'NewPassword'. Cannot convert the "System.Security.SecureString" value
of type "System.String" to type "System.Security.SecureString".
At line:1 char:38
+ Set-SecretStorePassword -NewPassword System.Security.SecureString
+                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-SecretStorePassword], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.SecretStore.SetSecretStorePasswordCo
   mmand

PS C:\Users\k> pSet-SecretStorePassword -NewPassword '123'
Set-SecretStorePassword : Cannot bind parameter 'NewPassword'. Cannot convert the "123" value of type "System.Int32"
to type "System.Security.SecureString".
At line:1 char:38
+ Set-SecretStorePassword -NewPassword 123
+                                      ~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-SecretStorePassword], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.SecretStore.SetSecretStorePasswordCo
   mmand

Relevant documentation below:

Set-SecretStorePassword -NewPassword [-Password ]

with

-Password Existing password needed to unlock the store. This can be ignored if the store doesn't currently use a password.

Any idea how to fix this? Thank you!

SydneyhSmith commented 2 years ago

Thanks @Kaiyiccc to set the SecretStore to have no password use the Set-SecretStoreConfiguration cmdlet with the -Authentication None parameter https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.secretstore/set-secretstoreconfiguration?view=ps-modules#parameters