Templates/Config.ps1
|
#region optional module settings (never writes into the module folder) # Loads module-scoped variables from Config.psd1 in the user's settings folder for this module # (<settings root>/<ModuleName>/Config.psd1, see Get-ModuleConfig). The module folder is never written to, # so this works for modules installed for all users. Create the file yourself, for example: # @{ ApiBaseUri = 'https://api.example.com' } # Store secrets with Protect-ConfigValue and read them with Unprotect-ConfigValue. try { $ModuleSettings = Get-ModuleConfig -CommandPath $PSCommandPath -ErrorAction Stop $ConfigFilePath = Join-Path -Path $ModuleSettings.ModuleConfigPath -ChildPath 'Config.psd1' if (Test-Path -Path $ConfigFilePath -PathType Leaf) { $ModuleVariables = Import-PowerShellDataFile -Path $ConfigFilePath -ErrorAction Stop foreach ($VariableName in $ModuleVariables.Keys) { Write-Verbose "Setting module variable '$VariableName' from '$ConfigFilePath'." Set-Variable -Name $VariableName -Value $ModuleVariables[$VariableName] -Scope Script -Force } } else { Write-Verbose "No module settings file at '$ConfigFilePath'; module variables were not loaded." } } catch { Write-Warning "Module settings could not be loaded: $($_.Exception.Message)" } #endregion |