Code Monkey home page Code Monkey logo

Comments (2)

dlwyatt avatar dlwyatt commented on August 12, 2024

You're on the right track. When you use the Add-DscEncryptedPassword command to set up your encrypted credentials in source control, Get-DscConfigurationData will put those all into a hashtable at $ConfigurationData['Credentials']. In combination with that, you might also have a property that you can resolve with Resolve-DscConfigurationProperty to determine which account to use from the Credentials table. Something like this:

$accountName = Resolve-DscConfigurationProperty -Node $Node -PropertyName 'TheAccount'
$psCredential = $ConfigurationData['Credentials'][$accountName]

someResource someName
{
    Credential = $psCredential
}

from dsc.

tysonjhayes avatar tysonjhayes commented on August 12, 2024

OK after playing around with it I was never able to get your way to work.

Exploring the code I found that the issue with calling it the way you described is that the scripts set it as an Object[] not a hashtable as you can see from the code below.

[1:09:18 PM] [0048] » $script:ConfigurationData['Credentials']

Name                           Value
----                           -----
testaccount                    System.Management.Automation.PSCredential
testaccount2               System.Management.Automation.PSCredential


[1:09:24 PM] [0049] » $script:ConfigurationData['Credentials']['testaccount']
[1:09:29 PM] [0050] » $script:ConfigurationData['Credentials'] | gm


   TypeName: System.Collections.Hashtable

[1:09:34 PM] [0051] » ($script:ConfigurationData['Credentials']).getType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

If I were to go into Get-CredentialConfigurationData.ps1 and change

$script:ConfigurationData.Credentials = Get-ChildItem -Path $credentialsPath |
            Get-DscEncryptedPassword -StoreName { $_.Name -replace '\.encrypted' -replace '\.psd1' }

to

foreach ($item in (Get-ChildItem -Path $credentialsPath))
{
    $name = ( $item.Name -replace '\.encrypted' -replace '\.psd1' )
    $value = (Get-DscEncryptedPassword -StoreName ( $item.Name -replace '\.encrypted' -replace '\.psd1' ) -Path $item.DirectoryName)
    $script:ConfigurationData.Credentials.Add($name, $value[$name])
}

I can actually get the objects back like you are suggestion I should be able to:

[1:22:36 PM] [0111] » $script:ConfigurationDAta['Credentials']

Name                           Value
----                           -----
testaccount2                   System.Management.Automation.PSCredential
testaccount                    System.Management.Automation.PSCredential


[1:22:42 PM] [0112] » $script:ConfigurationDAta['Credentials']['testaccount2']

UserName                         Password
--------                         --------
testaccount2 System.Security.SecureString

[1:22:49 PM] [0113] » ($script:ConfigurationDAta['Credentials']).gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Hashtable                                System.Object

If it matters I'm on the development branch with WMF 4.0

from dsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.