functions/public/Confirm-Configurations.ps1
function Confirm-Configurations { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [Hashtable] $config, [Parameter(Mandatory = $true)] [Hashtable] $checkList ) begin { $results = @(); function Invoke-Check { [CmdletBinding()] param ( [Parameter(Position = 0, Mandatory = $true)] [string] $name, [Parameter(Position = 1)] [object[]] $checkList ) $result = @(); $splat = @{ name = $name type = $config["_type_"][$name] value = $config[$name] } switch ($checkList) { "isNotNull" { $result += Confirm-IsNotNull @splat } "isValidPath" { $result += Confirm-IsValidPath @splat } "isValidDir" { $result += Confirm-IsValidDir @splat } "isBoolean" { $result += Confirm-IsBoolean @splat } "isValidConnection" { $result += Confirm-IsValidConnection @splat } "isValidEndpoint" { $result += Confirm-IsValidEndpoint @splat } } return $result } } process { foreach ($item in $checkList.Keys) { if ($config.ContainsKey($item)) { $results += Invoke-Check $item $checkList[$item] } else { Write-DosMessage -Level "Warning" -Message "Unable to find $item as a configuration. Please remove from checklist." } } } end { $errors = $results | Where-Object errorFlag -eq 1 $warnings = $results | Where-Object errorFlag -eq -1 $success = $results | Where-Object errorFlag -eq 0 $errorsCnt = ($errors | Measure-Object).Count $warningsCnt = ($warnings | Measure-Object).Count $successCnt = ($success | Measure-Object).Count if ($warnings) { $msg = ($warnings | Sort-Object type, name | Format-Table name, type, check, @{Label = "result"; Expression = {"warning"}}, message -Wrap) Write-DosMessage -Level "Warning" -Message "WARNINGS: $warningsCnt >>>`n$(($msg | Out-String).trim())" } if ($errors) { $msg = ($errors | Sort-Object type, name | Format-Table name, type, check, @{Label = "result"; Expression = {"failed"}}, message -Wrap) Write-DosMessage -Level "Fatal" -Message "ERRORS: $errorsCnt >>>`n$(($msg | Out-String).trim())" } Write-DosMessage -Level "Information" -Message "Configuruation checks summary - Success: $successCnt, Warnings: $warningsCnt, Errors: $errorsCnt" } } |