param([Parameter(Mandatory)][string]$EvidenceDir,[string[]]$Sources) $ErrorActionPreference='Stop' New-Item -ItemType Directory -Path $EvidenceDir -Force|Out-Null if(!$Sources){$Sources=@(Get-ChildItem $PSScriptRoot -Filter '*.ps1'|Select-Object -ExpandProperty FullName)} $results=@(foreach($source in $Sources){ $errors=$null $ast=[Management.Automation.Language.Parser]::ParseFile($source,[ref]$null,[ref]$errors) $malformed=@($ast.FindAll({param($n)$n-is[Management.Automation.Language.CommandParameterAst]-and$n.ParameterName-match'^(eq|ne|gt|lt|ge|le)\d+$'},$true)|ForEach-Object{$_.Extent.Text}) @{source=$source;passed=($errors.Count-eq0-and$malformed.Count-eq0);malformedOperatorParameters=$malformed;errors=@($errors|Select-Object ErrorId,Message,@{n='line';e={$_.Extent.StartLineNumber}})} }) $passed=$results.Count-gt0-and@($results|Where-Object passed -ne $true).Count-eq0 @{passed=$passed;checks=$results}|ConvertTo-Json -Depth 8|Set-Content (Join-Path $EvidenceDir 'syntax-result.json') if(!$passed){exit 1};exit 0