Repository navigation
Fix Windows PowerShell 5.1 import failure from non-ASCII module source (#1603) - #1611
Eduard Arbona (earbona23) wants to merge 3 commits into
Conversation
microsoftgraph#1603) The per-cmdlet source files under the Applications and Beta.Applications modules contained non-ASCII characters (the arrow "->", em/en dashes, and check marks) inside comments and Write-Host/Write-Verbose strings. These files are concatenated without a BOM into the shipped .psm1. Windows PowerShell 5.1 decodes a BOM-less file using the system ANSI code page instead of UTF-8, so each multi-byte character turns into stray quote characters that unbalance the surrounding strings. The parser then fails with "Missing closing ')' in expression" and "The string is missing the terminator", and Import-Module aborts. PowerShell 7 (Core) reads BOM-less files as UTF-8, which is why CI and PowerShell 7 users never saw the break. Replace the non-ASCII characters with ASCII equivalents so the generated module parses identically under every encoding. Two Users cmdlet files carried the same non-ASCII-without-BOM hazard (a curly apostrophe in a HelpMessage) and are cleaned as well. Add a Pester regression test that fails if any module source file reintroduces non-ASCII bytes. Fixes microsoftgraph#1603
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Learn Build status updates of commit 0b53622: ❌ Validation status: errorsPlease follow instructions here which may help to resolve issue.
For more details, please refer to the build report. Note: Your PR may contain errors or warnings or suggestions unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them. |
|
Flagging that the red The failure is The same status is red on every recent open PR in this repo (#1601, #1572, #1529), so it looks like a docset configuration issue rather than per-PR validation. Happy to rebase if a fix lands. |
There was a problem hiding this comment.
Suggested action: Approve — reviewed commit 0b5362241f804f094e179b6b067d3d0d9c603b1f.1
The source changes address #1603: the affected non-ASCII characters are replaced with ASCII without changing the cmdlets' control flow or Graph requests.
- Independently scanned all 639 module PowerShell source files at this commit: no non-ASCII bytes remain.
- Decoded the 16 changed production files using Windows-1252 and parsed them: zero parser errors.
- Ran the new Pester regression file under PowerShell 7.6.7/Pester 5.9.1: 641 passed.
- No new security-sensitive behavior or material production regression found in this diff.
Nonblocking test-portability note: Join-Path $PSScriptRoot '..' '..' 'module' in the new test uses the PowerShell 6+ overload. Windows PowerShell 5.1 rejects that invocation; use nested joins if the guard itself must run there. This does not affect the shipped cmdlet fix.
Limitations: I did not build and import every packaged module on Windows PowerShell 5.1. OpenPublishing remains red with a moniker-mapping configuration error; that file is unchanged here, but the overall checks are not all green.
Footnotes
-
AI-assisted review by Codex (1 agent). Model:
gpt-6-astra. Configured reasoning effort:high(verified from the review session metadata). Review effort: detailed source review with the validation described above. Skill:engineering:code-review. Tools: GitHub API/CLI, Git, PowerShell source analysis and isolated runtime probes. ↩
The regression guard added for microsoftgraph#1603 resolved the module root with `Join-Path $PSScriptRoot '..' '..' 'module'`. The third positional argument binds to -AdditionalChildPath, introduced in PowerShell 6. Windows PowerShell 5.1 only accepts -Path and -ChildPath, so it rejects that invocation with a parameter binding error. That left the guard unable to run on the one platform the fix targets: validating microsoftgraph#1603 under Windows PowerShell 5.1 would fail before a single source file was checked. Replaced with nested Join-Path calls, which resolve identically on both editions. What the guard asserts is unchanged: 641 tests pass.
|
Thanks for the review, Sam Erde (@SamErde). Boss I applied the test-portability note, and it turned out to be more than cosmetic. The guard resolved the module root with That means the regression guard for #1603 could not run on the one edition the fix targets: anyone validating this under Windows PowerShell 5.1 would hit the binding error before a single source file was read. A guard that cannot execute where the bug lives reports nothing. Fixed in 2751155 with nested
Only the test file changed; the 16 cmdlet source files are untouched. Sorry for the extra review round on an approved commit - the change is three lines and does not alter what the guard asserts. On |
|
Learn Build status updates of commit 2751155: ❌ Validation status: errorsPlease follow instructions here which may help to resolve issue.
For more details, please refer to the build report. Note: Your PR may contain errors or warnings or suggestions unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them. |
|
Learn Build status updates of commit 81a7287: ❌ Validation status: errorsPlease follow instructions here which may help to resolve issue.
For more details, please refer to the build report. Note: Your PR may contain errors or warnings or suggestions unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them. |
Eduard Arbona (earbona23)
left a comment
There was a problem hiding this comment.
Status, for a maintainer with write access:
Approved by Sam Erde (@SamErde) and green on everything in its control: CLA and
GitOps/AdvancedSecurity both pass. The only red is OpenPublishing.Build, and it
is not from this branch. It fails with the same PSMD2Yaml_FileLoadFailed on
module/mapping/monikerMapping.json on every recent PR in this repo (root cause
and fix in #1616). This PR changes only source-file encoding in 16 cmdlet files
plus one regression test; it touches no docs or mapping file.
Two items are outside my control as the author:
- 1es-EntraPowerShell-PR is marked "expected" but has never reported. It likely
needs /azp run from an authorized pipeline user. - Merging is blocked on a code-owner review from
microsoftgraph/msgraph-ps-compatibility-azuread-write.
Happy to rebase onto the latest main whenever a maintainer prefers; I held off to
avoid rewriting history under an active review.
Thanks for taking a look broo
|
Status, for a maintainer with write access: This is approved by Sam Erde (@SamErde) and green on everything in its control: CLA and GitOps/AdvancedSecurity both pass. The only red is OpenPublishing.Build, and it is not from this branch. It fails with the same Two items are outside my control as the author:
Happy to rebase onto the latest main whenever a maintainer prefers; I held off to avoid rewriting history under an active review. Thanks for taking a look. |
|
Ran the Windows PowerShell 5.1 checks that were still missing, on Windows (PS 5.1.26100 and PS 7.6.6, Pester 5.7.1):
I didn't run the full module build on 5.1, since it pins Microsoft.Graph 2.25.0 and I don't have that side by side. |
|
The module's pin to Microsoft.Graph.Authentication 2.25.0 should be removed (or bumped to a newer version) as there are some known issues with a few interim releases. This warrants a new issue/request, but to be honest, I'm not sure if Microsoft has a team dedicated to this module anymore. |
|
Thanks Sam Erde (@SamErde). I measured the shipped artifact before answering, because "the pin" turns out to be two separate knobs that pull in opposite directions. The published manifest is a floor, not an exact pin.
RequiredModules = @(@{ModuleName = 'Microsoft.Graph.Authentication'; ModuleVersion = '2.25.0'; })
So consumers are not held at 2.25.0 today. Removing that entry would not unblock a newer release, it would only let versions below 2.25.0 satisfy the requirement. The exact pin lives in the build toolchain, and that one does bite.
That is what forces a contributor's machine and the pipeline onto 2.25.0, published 2024-11-21, with 23 stable releases shipped since (2.26.0 through 2.41.2, the latest published 2026-10-14). It is also the reason I could not run the full module build on 5.1 for this PR. One trap for whoever takes it on. The two
And a manifest has no maximum version field, so a floor cannot exclude a bad interim release that sits above it. Raising the floor skips the bad ones below the new value, and nothing more. Happy to open the issue with these measurements, and to send the bump as its own PR so this one stays scoped to the encoding fix. Which target would you prefer, latest 2.41.2 or a specific known good version? |
|
Eduard Arbona (@earbona23), that assessment is (obviously) 😀 correct. However, there are some potentially unexpected behaviors that should be known, depending on whether the user runs The breakdown
It's not necessarily a big problem, but can be annoying if users don't know to expect this. |
|
Good point, thanks. I hadn't looked at it from the PSResourceGet side. I checked the one case I could reproduce here. Against PSGallery, with PowerShell 7.6.6 on Linux, saving
So on the Gallery today both land on latest. That fits your description, though. If 1.2.0 keeps whichever candidate comes last in the feed response, PSGallery just happens to order them in a way that works. A private feed (Artifacts, a NuGet v3 mirror) could order them differently and land someone on 2.25.0 exactly. That makes the floor matter more than I said above, and it's a good argument for raising it to a known good version rather than just dropping it. I'll open a separate issue for the build pin and the floor, with both keys listed so they move together, and keep this PR scoped to the 5.1 encoding fix. |
|
Checking in on this one, with no change on my side since 21 October. Current state, for anyone with write access who picks this up:
On the dependency question we closed out: the published manifest is a floor rather than an exact pin, and the If anything here needs rework rather than a merge, say so and I will take it. I would rather it be rejected with a reason than sit. |
Description
Import-Module Microsoft.Entra.Applications(andMicrosoft.Entra.Beta.Applications) throws parser errors on Windows PowerShell 5.1 in 1.3.0, as reported in #1603.Root cause
The shipped
.psm1is assembled by concatenating the per-cmdlet.ps1source files and is written without a BOM. Several of the new AgentId / Blueprint / MCPServer source files contain non-ASCII characters (→, em/en dashes,✓) in comments and inWrite-Host/Write-Verbosestrings.Windows PowerShell 5.1 decodes a BOM-less file with the system ANSI code page rather than UTF-8, so each multi-byte character becomes a stray curly-quote that unbalances the surrounding string. The parser then fails with
Missing closing ')' in expressionandThe string is missing the terminator, and the import aborts. PowerShell 7 reads BOM-less files as UTF-8, so CI and PowerShell 7 users never hit this.Fix
→→->, dashes→-,✓→[OK]). ASCII parses identically under every encoding.Userscmdlet files carried the same non-ASCII-without-BOM hazard (a curly apostrophe in aHelpMessage); they are cleaned as well so the source tree is fully ASCII. Those two do not break the import, only garble help text, but they trip the same PSScriptAnalyzer rule.test/Entra/SourceFileEncoding.Tests.ps1, a Pester regression test that fails if anymodule/**/*.ps1reintroduces non-ASCII bytes.Testing
Invoke-ScriptAnalyzerno longer reportsPSUseBOMForUnicodeEncodedFileon any of the changed files (16 findings removed, no new findings).Fixes #1603