Skip to content

Add -NoProfile to elevated Run-Command subprocess#41

Merged
drissboumlik merged 3 commits into
usepvm:masterfrom
mattlindell:master
Apr 18, 2026
Merged

Add -NoProfile to elevated Run-Command subprocess#41
drissboumlik merged 3 commits into
usepvm:masterfrom
mattlindell:master

Conversation

@mattlindell
Copy link
Copy Markdown
Contributor

@mattlindell mattlindell commented Apr 4, 2026

Summary

Run-Command spawns powershell.exe with -Verb RunAs but loads the user's profile. If the profile contains interactive commands (e.g. a PS5→PS7 redirect), the hidden window hangs indefinitely.

Adding -NoProfile fixes this: an elevated subprocess running a single command has no need for user profiles.

Test plan

  • Added test verifying -NoProfile is passed to Start-Process
  • All 103 helpers tests pass

The elevated powershell.exe process spawned by Run-Command loads the
user's profile, which can cause hangs when the profile contains
interactive commands (e.g. a PS5→PS7 redirect guard). Adding -NoProfile
skips profile loading, which is correct for a utility subprocess that
only runs a single command.
Verifies that Run-Command passes -NoProfile to the elevated
powershell.exe subprocess, preventing user profiles from interfering
with the command execution.
@drissboumlik
Copy link
Copy Markdown
Collaborator

Hey @mattlindell

thank you very much for the PR
just one thing no need to import src\functions\helpers.ps1 in the test since it's loaded in the root file.
also may be we can pass -NoProfile too in pvm.bat .

Thanks again.

@mattlindell
Copy link
Copy Markdown
Contributor Author

Hey @mattlindell

thank you very much for the PR just one thing no need to import src\functions\helpers.ps1 in the test since it's loaded in the root file. also may be we can pass -NoProfile too in pvm.bat .

Thanks again.

Sure thing, I'll implement and push changes after work today. Thank you for the feedback!

@drissboumlik
Copy link
Copy Markdown
Collaborator

Sure thing, I'll implement and push changes after work today. Thank you for the feedback!

Thank you

Remove helpers.ps1 dot-source from Run-Command test — pvm.ps1 loads it
when running `pvm test`. Mirror Run-Command's -NoProfile fix in pvm.bat
so the top-level launcher also skips profile load.
@mattlindell
Copy link
Copy Markdown
Contributor Author

Both addressed in c0eba12:

  • Dropped the redundant helpers.ps1 dot-source from the Run-Command test.
  • Added -NoProfile to both pwsh and powershell branches in pvm.bat.

@drissboumlik
Copy link
Copy Markdown
Collaborator

Both addressed in c0eba12:

  • Dropped the redundant helpers.ps1 dot-source from the Run-Command test.
  • Added -NoProfile to both pwsh and powershell branches in pvm.bat.

Am merging this
Thanks @mattlindell again

@drissboumlik drissboumlik merged commit 3d0a0c6 into usepvm:master Apr 18, 2026
2 checks passed
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.

2 participants