Skip to content

Fix detection script to handle spinner lines and trailing count summaries in winget output#252

Open
hafometh88 wants to merge 2 commits into
svrooij:mainfrom
hafometh88:fix/detection-output-parsing
Open

Fix detection script to handle spinner lines and trailing count summaries in winget output#252
hafometh88 wants to merge 2 commits into
svrooij:mainfrom
hafometh88:fix/detection-output-parsing

Conversation

@hafometh88

Copy link
Copy Markdown

Fixes the auto-generated detection scripts that use winget list to check
whether an app installed by Intune is present. Apps were consistently
reported as not installed even when they were.

Recent winget versions (1.7+) write progress spinner lines to stdout before
the package table, and some versions append a N package(s) count line
after it. The parser assumed the first alpha line was the header and the
last line was the data row. Both assumptions break with the new output
format:

""
"   - "           ← spinner lines captured in stdout
"   \ "
"Name   Id   Version   Source"
"-----------------------------"
"7-Zip  7zip.7zip  26.00  winget"
"1 package(s)"    ← trailing count line in some versions

The header and data row are now anchored on the separator line (^-{10,})
which is stable across all winget versions and unaffected by anything
prepended or appended around the table.

Also fixed a latent ArgumentOutOfRangeException in Substring() that
would crash the script when a data row is shorter than the last header
column position (e.g. when the Available and Source fields are blank and
winget trims trailing whitespace).

… count summaries

Anchor header and data row extraction on the separator line ('^-{10,}')
instead of assuming the first alpha line is the header and the last line
is the data row.

Recent winget versions (1.7+) prepend progress spinner lines to stdout,
and some versions append a "N package(s)" count summary. Both caused
the parser to pick the wrong rows, resulting in exit 10 even when the
package was installed.

Also guard Substring() against out-of-bounds access when the data row
is shorter than the last header column position (e.g. when Available
and Source fields are blank and trailing whitespace is trimmed).
@hafometh88

Copy link
Copy Markdown
Author

@svrooij Hello, is this project still being maintained?

@svrooij

svrooij commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Yes it is, but my notifications where off for some reason

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the WinGet-based Intune detection script parsing so it correctly identifies installed apps across newer winget versions that emit progress/spinner lines before the table and may append a trailing N package(s) summary line after it.

Changes:

  • Anchor table parsing on the dashed separator line (^-{10,}) rather than assuming the first alpha line is the header and the last line is the data row.
  • Prevent Substring() from throwing when data rows are shorter than expected (e.g., trailing columns are blank and whitespace is trimmed).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@svrooij

svrooij commented Jun 12, 2026

Copy link
Copy Markdown
Owner

@hafometh88 I would like to run codeql first on the commits, but github is messing with me, would you be able to do this:

git commit --allow-empty -m "trigger CI" && git push
image

which should trigger the workflow engine

@hafometh88

Copy link
Copy Markdown
Author

@svrooij done

@hafometh88

Copy link
Copy Markdown
Author

@svrooij the Build and Test C# failure isn't from this PR. It's dotnet format --verify-no-changes failing on 18 pre-existing .cs files that want a blank line after namespace X;. This PR only changes WingetDetection.ps1.

The workflow pins 8.x | 9.x with no global.json, and the ubuntu-24.04 runner now has the .NET 10 SDK, whose formatter enforces that rule. Fails under 10.0.301, passes under 9.0.315. main would fail too if re-run.

I can push the formatting pass or do you want to do it yourself later on main?

@svrooij

svrooij commented Jun 13, 2026

Copy link
Copy Markdown
Owner

No this is not your fault, I'll fix it.
We are in different timezones I will merge both on monday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants