PrivateFunctions/Validate-CheckJsonFile.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
Function Validate-CheckJsonFile { [OutputType([Boolean])] [CmdletBinding()] Param( [String] $CheckJsonFile ) If (-not(Test-Path -Path $CheckJsonFile -PathType Leaf)) { Write-Host "Het bestand '$($CheckJsonFile)' kon niet worden gevonden." Return $False; } $CheckJsonRaw = Get-Content $CheckJsonFile -Raw -ErrorAction Ignore if (!$CheckJsonRaw) { Write-Error "Fout ontstaan bij inlezen van bestand '$($CheckJsonFile)'." Return; } Write-Verbose "Validatie voor geldige JSON..." Try { $CheckJsonObject = $CheckJsonRaw | ConvertFrom-Json } Catch { Write-Host "Opgegeven bestand '$($CheckJsonFile)' bevat geen geldige JSON. Gebruik bij twijfel een JSON validator (bijv. https://jsonlint.com/) om je JSON bestand te controleren." -ForegroundColor Red Return $False; } If (-not($CheckJsonObject.PSobject.Properties.name -match "checks") -or $CheckJsonObject.checks.Count -eq 0) { Write-Host "Opgegeven bestand '$($CheckJsonFile)' bevat geen controles of deze is leeg." -ForegroundColor Red Return $False; } Write-Verbose "JSON validatie voltooid." Return $True } |