diff --git a/pvm.bat b/pvm.bat index f55c13d..813c603 100644 --- a/pvm.bat +++ b/pvm.bat @@ -10,9 +10,9 @@ set "ARGS=%ARGS:-- =%" where pwsh >nul 2>&1 if %ERRORLEVEL%==0 ( - pwsh -ExecutionPolicy Bypass -File "%FILE_TARGET%" %ARGS% + pwsh -NoProfile -ExecutionPolicy Bypass -File "%FILE_TARGET%" %ARGS% ) else ( - powershell -ExecutionPolicy Bypass -File "%FILE_TARGET%" %ARGS% + powershell -NoProfile -ExecutionPolicy Bypass -File "%FILE_TARGET%" %ARGS% ) endlocal diff --git a/src/functions/helpers.ps1 b/src/functions/helpers.ps1 index 7836d91..f679593 100644 --- a/src/functions/helpers.ps1 +++ b/src/functions/helpers.ps1 @@ -212,7 +212,7 @@ function Make-Symbolic-Link { function Run-Command { param($command) - $process = Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -Command `"$command`"" -Verb RunAs -WindowStyle Hidden -PassThru -Wait + $process = Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$command`"" -Verb RunAs -WindowStyle Hidden -PassThru -Wait $process.WaitForExit() return $process.ExitCode } diff --git a/tests/helpers.tests.ps1 b/tests/helpers.tests.ps1 index 7ede0b6..d15412c 100644 --- a/tests/helpers.tests.ps1 +++ b/tests/helpers.tests.ps1 @@ -1350,3 +1350,19 @@ Describe "Get-BinaryArchitecture-From-DLL" { } } } + +Describe "Run-Command" { + Context "When executing elevated commands" { + It "Passes -NoProfile to prevent user profile from loading" { + $mockProcess = [PSCustomObject]@{ ExitCode = 0 } + $mockProcess | Add-Member -MemberType ScriptMethod -Name WaitForExit -Value {} + Mock Start-Process { return $mockProcess } + + $result = Run-Command -command "echo test" + + Should -Invoke Start-Process -Times 1 -ParameterFilter { + $ArgumentList -like "*-NoProfile*" + } + } + } +}