Variables.ps1 and PSCredentials

PowerShellUniversal 2.3.0

I am currently using authentication.ps1 to store users’ credentials in Windows Authentication Manager after that log in to access a dashbaord. I noticed that the following code is added to Variables.ps1 file automatically:

 "New-PSUVariable -Name "userName1" -Value "BuiltInLocalVault" -Type "PSCredential" 

I’m curious to know how this is done automatically. Is there commands in another configuration file somewhere that I am missing? Is there a configuration file that automatically looks for credentials in Windows Credential manager, then the code listed above gets added to Variables.ps1 file?

When you create new secrets in PSU, it stores the actual value of the secret in the Windows Credential Manager and only references the secret in varaibles.ps1.

We are actually using the Microsoft Secret Management Module and calling Set-Secret to create the secret in the store. Then, when you want to use the variable, we call Get-Secret to load the secret from the store and pass it to the jobs or use it to start processes.

Ok, I think I am starting to connect the dots here. What I’m working with is not creating them within the PSU gui but allowing them to be created by the script (specifically in the authentication.ps1 file).

If I understand correctly, the rest API provided here Importing Secret Variables (with script) - #2 by adam creates the credentials as a PSU secret variable and then the Set-Secret creates the credentials in Windows Credential Manager. Is that correct? If I’m using the api call to create the credentials in PSU that way, do I still need to use Set-Secret to create them in Windows Credential manager as well?

@adam do you mind to elaborate on the different above (creating the credentials with the API vs Set-Secret and if both are needed for my situation)? Thanks!

If you create the credentials via the API, you won’t have to call Set-Secret because it does this internally.

@adam, it will be created both in PSU and windows credential manager?

Yep. Thats correct

@adam related question: These variables are supposed to be visible in dashboards correct? I set one and I can’t see it when starting my dashboard. PS 7.1.3 Framework 3.5.1

sandboxDashboard.ps1

New-UDDashboard -Title "Hello, World!" -Content {
    New-UDTypography -Text "Demo Mode: $MyTestVar"

    New-UDButton -Text "Learn more about Universal Dashboard" -OnClick {
        Invoke-UDRedirect https://docs.ironmansoftware.com
    }
}

variables.ps1

New-PSUVariable -Name "MyTestVar" -Value "ThisShouldWork" -Description "Test Var"

image

They are. In Environment.ps1, ensure that you have -Variables @(’*’) set on New-PSUEnvironment. That brings all variables into the environment.

OK so is it because I brought in a legacy config after an upgrade? I was expecting them to already be there:

That’s a misleading statement. I’ll update that. The are added by default to the default environments.

1 Like

That did fix it, thank you!

1 Like