fix: pass -NoProfile when invoking pwsh in requirement checks - #380
Merged
Julio Carlos Menendez (juliomenendez) merged 1 commit intoApr 21, 2026
Merged
Julio Carlos Menendez (juliomenendez) merged 1 commit into
Julio Carlos Menendez (juliomenendez) merged 1 commit into
Conversation
…t checks PowerShellModulesRequirementCheck.ExecutePowerShellCommandAsync launched pwsh with only -Command. Users whose PowerShell profile writes to stdout (e.g. a PSReadLine install prompt or posh-git warnings) would see that text prepended to the command output, causing int.TryParse of "$PSVersionTable.PSVersion.Major" to fail and the check to report "PowerShell is not available on this system" even on systems with pwsh 7+ installed. The same path is used for module detection and auto-install, which would silently misbehave for the same reason. MicrosoftGraphTokenProvider.BuildPowerShellArguments already uses "-NoProfile -NonInteractive" for pwsh; aligning this invocation with that convention. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Julio Carlos Menendez (juliomenendez)
requested a review
from a team
as a code owner
April 21, 2026 16:21
Julio Carlos Menendez (juliomenendez)
requested a review
from a team
as a code owner
April 21, 2026 16:21
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Copilot started reviewing on behalf of
Julio Carlos Menendez (juliomenendez)
April 21, 2026 16:21
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes PowerShell requirement checks in the Agent365 CLI deterministic by preventing user PowerShell profile scripts (and interactive prompts) from polluting stdout/stderr during subprocess execution.
Changes:
- Add
-NoProfile -NonInteractiveto thepwshinvocation used byPowerShellModulesRequirementCheckso version/module checks aren’t affected by profile output.
Julio Carlos Menendez (juliomenendez)
enabled auto-merge (squash)
April 21, 2026 16:38
Grant Harris (gwharris7)
approved these changes
Apr 21, 2026
Sellakumaran Kanagarathnam (sellakumaran)
approved these changes
Apr 21, 2026
Julio Carlos Menendez (juliomenendez)
deleted the
users/juliome/fix-pwsh-profile-pollution
branch
April 21, 2026 17:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PowerShellModulesRequirementCheck.ExecutePowerShellCommandAsyncinvokedpwshwith only-Command, so any output written by the user's PowerShell profile (PSReadLine install prompt, posh-git warnings, customWrite-Host, etc.) was prepended to stdout.int.TryParse("$PSVersionTable.PSVersion.Major"); profile pollution makes this fail and the CLI reportsPowerShell is not available on this systemeven when pwsh 7+ is installed.Get-Module/Install-Modulecalls on the same code path silently misbehave for the same reason.-NoProfile -NonInteractiveto the pwsh arguments. This matches the existing convention inMicrosoftGraphTokenProvider.BuildPowerShellArguments.Repro (before fix)
Any PowerShell profile that writes to stdout — for example one that imports
posh-gitor prompts for PSReadLine. Runninga365 setup all(ora365 setup requirements) produces:After the fix, the probe returns a clean
7regardless of profile contents and the check proceeds to module detection.Test plan
dotnet test --filter FullyQualifiedName~PowerShellModulesRequirementCheckTests— 5/5 passscripts/cli/install-cli.ps1;a365 setup requirementsprogresses past the PowerShell check on a machine with a profile that prints to stdout (previously blocked at this step)pwsh -NoProfile -Command "$PSVersionTable.PSVersion.Major"returns7cleanly with the same profile that polluted the unflagged call