Skip to content

Bring the module into line with ai-powershell-standards 2.0.0 (tracking) #77

Open

Description

@fadwen

Summary

ai-powershell-standards 2.0.0 was installed into this repository by pull requests #57 to #60. It replaced the earlier guidance with rules that carry IDs such as ERR-11 and STY-02, and several of them ask for things the module was not written to. This issue tracks the work of bringing the module into line. Each item below is one issue with its findings, a proposed change, and where needed a decision for the owner.

How the findings were produced

  • The standards' own check, Tools/Test-StandardsCompliance.ps1 at commit 79872d2 of ai-powershell-standards, run over this repository at commit d009d39 with PSScriptAnalyzer 1.25.0. It reports 2,919 findings: 2,512 of layout (STY-01, STY-02, STY-04, STY-07), 174 functions without help (DOC-01), 158 without [CmdletBinding()] (FUN-01), 56 throw statements in advanced functions (ERR-11), and a handful of others.
  • A parse of every .ps1 and .psm1 file for rules that check does not cover: help completeness, parameter types, pipeline parameters, -LiteralPath, encodings, version comparisons, and the test conventions.
  • A reading of the root module, the manifest, the build scripts, the workflows, the README and the help Markdown against the module, CI, README and PlatyPS rules.
  • The full Pester suite at commit d009d39 as a baseline, on one Windows 11 26H2 computer. PowerShell 7.6.10: 1,043 tests, 1,032 passed, 8 skipped, 3 failed, 95.11 percent coverage. Windows PowerShell 5.1: 996 passed, 44 skipped, the same 3 failed. The three failures are Repair-IntuneScript corrupts an ANSI script on a host with a UTF-8 system code page #75 and In-box module table does not list UOPProviders, present on Windows 11 26H2 #76 and do not occur in CI.

To repeat the first step from a checkout of ai-powershell-standards:

./Tools/Test-StandardsCompliance.ps1 -Path <path to IntuneScriptLab> -PassThru | Group-Object -Property RuleId

Issues

Requirements the module does not meet, in the order the changes stack most easily:

Decisions for the owner:

Defects found while the suites were run, which are not standards findings:

What already meets the rules

  • Version targets: the manifest and the root module both declare 5.1, the suites pass under Windows PowerShell 5.1 in CI, and the standards' check finds no command that exists only in Windows PowerShell.
  • Security basics: no Invoke-Expression, no secrets in source, credentials taken as [PSCredential] with the Credential() attribute, no prompt for a missing value in a function.
  • Release: an allowlist staging folder, an import of the staged copy in a new process, a check for empty URI keys, and -WhatIf that rehearses everything but the upload (MOD-10, MOD-13, MOD-14).
  • Help: Microsoft.PowerShell.PlatyPS 1.0.3, .EXTERNALHELP on every export, bare related links, an about_ topic, and a check on a case-sensitive file system.
  • Tests: the Pester 6.2.0 #Requires line and tags on every file, one assertion style, a shuffled run with a coverage gate in CI, and a Windows PowerShell 5.1 job.

Discovered and written up with Claude Code.

Activity

  1. added
    enhancement
    on Nov 22, 2026
  2. fadwen commented on Nov 23, 2026

    @fadwen
    OwnerAuthor

    Progress on the first items, as a stack of four pull requests. Each is based on the one before it, so they merge in this order:

    1. fix(release): bring the build scripts in line with the 2.0 standards #79 fix(release): the build and release scripts and the manifest. Closes Build and release scripts depart from the 2.0 standards (VER-05, MOD-12, SEC-50, ERR-01) #61.
    2. test(logs): build the event table before the test that reads it #80 test(logs): the order-dependent test found while the suites were run for fix(release): bring the build scripts in line with the 2.0 standards #79. Closes A Get-IslAgentLogEvent test fails when the shuffle runs it first in its file #78.
    3. ci: run every suite through one shuffled runner and rehearse releases #81 ci: one shuffled test runner for every job, pinned tools, a release rehearsal on pull requests, a nightly run and the security rules. Refs CI gates: failed blocks pass, runs are unshuffled, tools are unpinned, no release rehearsal (TST-42, TST-46, CIC-02, CIC-10, CIC-11) #62.
    4. ci: check text files out with LF on every platform #82 ci: .gitattributes and what follows from an LF checkout. Closes CI gates: failed blocks pass, runs are unshuffled, tools are unpinned, no release rehearsal (TST-42, TST-46, CIC-02, CIC-10, CIC-11) #62.

    quality-gates.yml starts by itself only for pull requests into main, which is #79. For the other three it was started by hand on the branch, and every job passed on each.

    Not started: #63 to #73. #63 (strict mode in the root module) and #64 (throw in advanced functions) change what the module does at run time, and the harness paths that run elevated, as SYSTEM or as another account are skipped on the hosted runners, so those two need a run on a lab device before they are proposed.

    Discovered and written up with Claude Code.

  3. fadwen commented on Nov 23, 2026

    @fadwen
    OwnerAuthor

    The stack has two more pull requests. Each is based on the one before it, so the whole stack merges in this order: #79, #80, #81, #82, #84, #85.

    1. fix(module): run under strict mode and fail the import on a load error #84 fix(module): strict mode in the root module, a loader that fails the import when a file fails to load, and every read the suites then reported. Closes Root module does not set strict mode or fail the import on a load error (ERR-02, ERR-03, MOD-05) #63.
    2. test: decide the skip conditions of four tests during discovery #85 test: four tests that were skipped on every run, found while fix(module): run under strict mode and fail the import on a load error #84 was run on a lab device. Closes Four tests never run: their -Skip condition reads a variable that BeforeAll sets after discovery #83.

    What was run for #84 beyond the hosted checks, because strict mode turns a silent $null into an error at run time on paths the hosted runners skip:

    Not started: #64 to #73. #64 (throw in advanced functions) is next, and needs the same run on a lab device.

    Discovered and written up with Claude Code.

  4. fadwen commented on Nov 23, 2026

    @fadwen
    OwnerAuthor

    The stack after the reviews of #79, #81, #82, #84 and #85. It merges in this order: #79, #80, #81, #82, #84, #87, #85.

    Review findings, each fixed on the branch of its pull request and merged upward through the stack

    New since the last comment

    State: quality-gates.yml passed on every branch of the stack after these changes; for the six that are not based on main it was started by hand. Not started: #64 to #73.

    Discovered and written up with Claude Code.

  5. fadwen commented on Nov 23, 2026

    @fadwen
    OwnerAuthor

    State after the merges of #79, #80, #81, #82 and #84 into main, which closed #61, #62, #63 and #78.

    Open pull requests, in merge order

    1. fix(harness): end a timed-out run without taskkill's errors #87 fix(harness): a timed-out run no longer fails on taskkill's messages under Windows PowerShell 5.1. test: decide the skip conditions of four tests during discovery #85 was merged into its branch, so it also carries the skip conditions that let the SYSTEM-context tests run. Closes A timed-out run throws on Windows PowerShell 5.1 when the caller's error preference is Stop #86 and Four tests never run: their -Skip condition reads a variable that BeforeAll sets after discovery #83. Approved; its checks pass.
    2. fix(logs)!: end the agent-log commands with terminating errors #89 fix(logs)!: the first area of Advanced functions end with throw instead of ThrowTerminatingError (ERR-10, ERR-11, ERR-14) #64, the commands that read the agent's logs. Stacked on fix(harness): end a timed-out run without taskkill's errors #87.

    #64 is larger than its title. Replacing a throw with ThrowTerminatingError lets the function that made the call carry on with nothing where the result should be, unless the call is inside a try with a catch. 49 of the 54 calls in the module to a function that can fail were not. The measurements and the order of work are in a comment on #64. #89 adds a test that holds the rule for the whole module and lists the calls still to convert, 46 after this first area. Three areas remain: the runtime harness, the tenant commands, and the analysis and rule commands.

    New issue

    Not started: #65 to #73.

    Discovered and written up with Claude Code.

  6. fadwen commented on Nov 23, 2026

    @fadwen
    OwnerAuthor

    Two decisions were made and both are implemented.

    ERR-13 for the log files (#89). Get-IntuneAgentLog reports a path that does not exist, and a log it cannot read or parse, for that one item and goes on with the others. Get-IntuneAgentTimeline and Export-IntuneAgentDiagnostic read the logs through it, so they give what the readable logs hold.

    -WhatIf previews a run (#88, pull request #90). The five Invoke-Intune*Test commands, the two Export- commands and Get-IntuneScriptHealth ask ShouldProcess before they run a script or write anything, and nothing inside the module consults the preference any more.

    Open pull requests, in merge order

    1. fix(harness): end a timed-out run without taskkill's errors #87 fix(harness): closes A timed-out run throws on Windows PowerShell 5.1 when the caller's error preference is Stop #86 and Four tests never run: their -Skip condition reads a variable that BeforeAll sets after discovery #83. Approved.
    2. fix(logs)!: end the agent-log commands with terminating errors #89 fix(logs)!: the first area of Advanced functions end with throw instead of ThrowTerminatingError (ERR-10, ERR-11, ERR-14) #64, with ERR-13.
    3. feat(harness): preview a run with -WhatIf instead of half-running it #90 feat(harness): closes Under a WhatIf preference the harness skips its preparation and still starts the host #88.

    quality-gates.yml passed on all three; for #89 and #90 it was started by hand. #90 was also run on a lab device as SYSTEM under Windows PowerShell 5.1: every suite, 1,068 passed and none failed.

    Still open in #64: the runtime harness, the tenant commands, and the analysis and rule commands. 46 calls still rely on a throw in the function they call; the list is in Tests/Unit/Module.ErrorFlow.Tests.ps1.

    Not started: #65 to #73.

    Discovered and written up with Claude Code.

  7. fadwen commented on Nov 24, 2026

    @fadwen
    OwnerAuthor

    State after the merges of #87, #89 and #90 into main, which closed #83, #86 and #88.

    Open pull request

    What #92 does

    • The five Invoke-Intune*Test commands and the functions they launch through raise their failures with ThrowTerminatingError and an ID each, and every call of such a function is inside a try with a catch.
    • ERR-13 for the three commands that take scripts from the pipeline: a script that cannot be run is reported for that script, and the next one still runs.
    • Grant-IslFolderAccess no longer sets $ErrorActionPreference (ERR-02): icacls.exe and taskkill.exe run through one private function that starts a process and reads its streams.

    Checked: every suite locally on PowerShell 7.6.10 and Windows PowerShell 5.1, on a lab device as SYSTEM under Windows PowerShell 5.1 (1,095 passed, none failed, with the SYSTEM-context tests and the tests that run as another account), the release rehearsal, and quality-gates.yml on the last commit, all five jobs.

    Still open in #64: the tenant commands, and the analysis and rule commands. 33 calls still rely on a throw in the function they call, down from 46; the list is in Tests/Unit/Module.ErrorFlow.Tests.ps1. The pull requests for those areas will be stacked on #92.

    Not started: #65 to #73.

    Discovered and written up with Claude Code.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions