From 6fe5a7bd77bcac9cceb1973ac503fb2b5e1a2d69 Mon Sep 17 00:00:00 2001 From: machinewrapped Date: Sun, 25 Oct 2026 07:55:46 +0100 Subject: [PATCH] Fix PSScriptAnalyzer job failing on push The PSScriptAnalyzer workflow failed on pushes to master with "Object reference not set to an instance of an object", thrown from Invoke-ScriptAnalyzer. The step was reporting a crash, not lint findings. Cause: the step ran Get-ChildItem -Filter *.ps1 and *.psm1 and piped the FileInfo objects into Invoke-ScriptAnalyzer. Piping those objects into the analyzer triggers a null reference inside PSScriptAnalyzer. Passing the same files by path does not. Because the error is raised inside the analyzer, the job failed even though the lint itself found no Error-severity issues. Fix: replace the two piped calls with a single $results = @(Invoke-ScriptAnalyzer -Path . -Recurse). This analyzes .ps1, .psm1 and .psd1 under the repo, which matches the workflow's path filters. The Error check and exit code are unchanged. Also add .github/workflows/scriptAnalyzer.yaml to the pull_request and push path filters, so edits to the analyzer job itself trigger a run. Verification: locally, the piped form reproduces the error, while -Path . -Recurse completes with 1063 findings and 0 Error-severity findings. On this PR, the PSScriptAnalyzer job passes for both the pull_request and push events. Co-Authored-By: Claude Haiku 5.5 --- .github/workflows/scriptAnalyzer.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scriptAnalyzer.yaml b/.github/workflows/scriptAnalyzer.yaml index 566d5e1272884..79ff49461f34e 100644 --- a/.github/workflows/scriptAnalyzer.yaml +++ b/.github/workflows/scriptAnalyzer.yaml @@ -8,11 +8,13 @@ on: - "**/*.ps1" - "**/*.psm1" - "**/*.psd1" + - ".github/workflows/scriptAnalyzer.yaml" push: paths: - "**/*.ps1" - "**/*.psm1" - "**/*.psd1" + - ".github/workflows/scriptAnalyzer.yaml" permissions: contents: read # Needed to check out the code @@ -32,8 +34,7 @@ jobs: - name: Run PSScriptAnalyzer run: | # Run PSScriptAnalyzer on all PowerShell scripts - $results = @(Get-ChildItem -Recurse -Filter *.ps1 | Invoke-ScriptAnalyzer) - $results += @(Get-ChildItem -Recurse -Filter *.psm1 | Invoke-ScriptAnalyzer) + $results = @(Invoke-ScriptAnalyzer -Path . -Recurse) if ($results) { Write-Output $results | Format-List -GroupBy ScriptName }