Skip to content

Add -NoProfile to elevated Run-Command subprocess#41

Open
mattlindell wants to merge 2 commits intousepvm:masterfrom
mattlindell:master
Open

Add -NoProfile to elevated Run-Command subprocess#41
mattlindell wants to merge 2 commits intousepvm:masterfrom
mattlindell:master

Conversation

@mattlindell
Copy link
Copy Markdown

@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
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

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