Importing Secret Variables (with script)

Product: PowerShell Universal
Version: 2.3.0

How can I import the credentials that are stored in Windows Credential manager into PowerShell Universal as a secret variable as part of my code? I can do this manually using the GUI, but I need this to be done as part of the dashboard script so that the user’s credentials are available/accessible during runtime.

It looks like we have an issue with the cmdlet but you can call the REST API directly to create secrets in PSU.

Invoke-RestMethod http://localhost:5000/api/v1/variable -METHOD Post -Body (@{
   name = "Secret"
   type = "PSCredential"
   userName = "Adam"
   password = "Password"
   vault = "BuiltInLocalVault"
} | ConvertTo-Json) -Headers @{ Authorization = "Bearer $AppToken" } -ContentType 'application/json'

Thanks @adam. Is there a way to do this without hard coding usernames? I wanting to import the users’ credentials every time a new user accesses the dashboard. Is there a way to import all available credentials listed in Windows Credential Manager as opposed to manually typing in a specific username/password?

In your authentication.ps1 file, you can use the $Credential that is provided.

param($Credential)

Invoke-RestMethod http://localhost:5000/api/v1/variable -METHOD Post -Body (@{
   name = $Credential.UserName
   type = "PSCredential"
   userName = $Credential.UserName
   password = $Credential.GetNetworkCredential().Password
   vault = "BuiltInLocalVault"
} | ConvertTo-Json) -Headers @{ Authorization = "Bearer $AppToken" } -ContentType 'application/json'

I added the provided code to my authentication.ps1 file and that was exactly what I needed. I am now storing the user’s credentials in PSU as a secret variable. Thanks!