# Test-ScriptSyntax.ps1 - parses all .ps1 files without executing them
param([string] $Path = ".")

Get-ChildItem -Path $Path -Filter *.ps1 | ForEach-Object {
  $tokens = $null
  $errors = $null
  [System.Management.Automation.Language.Parser]::ParseFile(
    $_.FullName, [ref]$tokens, [ref]$errors) | Out-Null
  if ($errors.Count -gt 0)
  {
    Write-Output "FAIL: $($_.Name) ($($errors.Count) Fehler)"
    $errors | ForEach-Object {
      Write-Output ("  Zeile {0}: {1}" -f $_.Extent.StartLineNumber, $_.Message)
    }
  }
  else
  {
    Write-Output "OK:   $($_.Name)"
  }
}