/PSModuleConfig

A generic configuration management module for Powershell modules.

Primary LanguagePowerShellBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

PSModuleConfig

A generic configuration management module for Powershell modules. PSModuleConfig offers a standardized way to store configuration parameters for other Powershell modules like URIs, User preferences, etc.

Usage

Create a new configuration with two config entries

New-PSModuleConfig -Name MyModule -Data @{"URI"="https://myapi.com"; "OtherParam"="SomedataHere"}

This will create the following file under $env:userprofile\PSModuleConfig\MyModule.json

{
    "psmoduleconfig":  {
                           "version":  "1.0.0",
                           "encrypt":  false
                       },
    "MyModule":  {
                     "OtherParam":  "SomedataHere",
                     "URI":  "https://myapi.com"
                 }
}

Create a new empty configuration and add the data later

New-PSModuleConfig -Name MyModule
Set-PSModuleConfig -Name MyModule -Key "URI" -Value "https://myapi.com"
Set-PSModuleConfig -Name MyModule -Key "OtherParam" -Value "SomedataHere"

Add multiple entries at once using a dictionary.

New-PSModuleConfig -Name MyModule
Set-PSModuleConfig -Name MyModule -Data @{"URI"="https://myapi.com"; "OtherParam"="SomedataHere"}

Protect an existing configuration

Enable-PSModuleConfigEncryption -Name MyModule

This will use ConvertFrom-SecureString with default settings to protect the configuration items (DPAPI on Windows). The known limitations of SecureString in memory apply. See Microsofts documentation for more details.

Disable like this.

Disable-PSModuleConfigEncryption -Name MyModule

You can also protect a new configuration right from the start using the New-PSModuleConfig command with the -Encrypt flag.

New-PSModuleConfig -Name MyModule -Data @{"URI"="https://myapi.com"; "OtherParam"="SomedataHere"} -Encrypt