Public/ps1/Configuration/General/Get-ApprxrConfigurationValue.ps1

<#
    .SYNOPSIS
    Retrieves a configuration value from the Apprxr config file.
 
    .DESCRIPTION
    Reads the specified configuration value from config.json. Supports returning secure strings and default values if the property does not exist.
 
    .PARAMETER name
    The name of the configuration property to retrieve.
 
    .PARAMETER secure
    If specified, returns the value as a secure string.
 
    .PARAMETER defaultValue
    The value to return if the property does not exist.
 
    .EXAMPLE
    Get-ApprxrConfigurationValue -name 'UserName' -secure
 
    .NOTES
    Used for accessing configuration values in Apprxr scripts and modules.
#>

function Get-ApprxrConfigurationValue{
    param($name,[switch]$secure, $defaultValue)

    $folder = Get-ApprxrConfigurationFolder

       
    if (Test-Path "$folder\config.json") {
    } else {
        "{}"|set-content "$folder\config.json"
    }

    $config = Get-Content "$folder\config.json" | ConvertFrom-Json
    # the prpoerty does not exist
    if (($config.$name -ne $null)) {
        if ($secure) {
            
            $secureString = $config.$name | ConvertTo-SecureString
            $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secureString)
            [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
        } else {
            $config.$name
        }
    } else {
        $defaultValue
    }
}