private/cmhealthutils.ps1

function Import-CmHealthSettings {
    [CmdletBinding()]
    param (
        [parameter()][string] $Primary = "$($env:USERPROFILE)\Desktop\cmhealth.json",
        [parameter()][string] $Default = "$(Split-Path $(Get-Module cmhealth).Path)\reserve\cmhealth.json"
    )
    try {
        if (Test-Path $Primary) {
            Write-Verbose "loading from: $Primary"
            $result = Get-Content -Path $Primary | ConvertFrom-Json
        } elseif (Test-Path $Default) {
            Write-Verbose "loading from: $Default"
            $result = Get-Content -Path $Default | ConvertFrom-Json
        } else {
            throw "cmhealth.json was not found"
        }
    }
    catch {
        Write-Error $_.Exception.Message 
    }
    finally {
        Write-Output $result
    }
}

function Get-CmHealthDefaultValue {
    [CmdletBinding()]
    param (
        [parameter(Mandatory)][ValidateNotNullOrEmpty()][string] $KeySet,
        [parameter(Mandatory)][ValidateNotNullOrEmpty()] $DataSet
    )
    try {
        $keydef = $KeySet -split ':'
        if ($keydef.Count -gt 1) {
            $keyname = $keydef[0]
            $value   = $keydef[1]
            $result  = $DataSet."$keyname"."$value"
        } else {
            $result = $DataSet."$keydef"
        }
    }
    catch {
        Write-Error $_.Exception.Message 
    }
    finally {
        Write-Output $result 
    }
}