Fix: PowerShell commands fail with custom profile scripts#403
Fix: PowerShell commands fail with custom profile scripts#403AmonReviled wants to merge 2 commits intohass-agent:mainfrom
Conversation
2e6a04d to
c097d96
Compare
|
Hello in the method Arguments = isScript
? $@"-NoProfile & '{command}'"
: $@"-NoProfile & {{{command}}}"put: Arguments = GetProcessArguments(command,"",isScript)This will make executing powershell more consistant and fix another issue. "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" "& {$PSVersionTable.PSVersion | Out-String}"For version 5.1 it works fine but for 7+ it is not: "C:\Program Files\PowerShell\7\pwsh.exe" "& {$PSVersionTable.PSVersion | Out-String}"gives an error. Using Best Regards |
@lukasz-lech-enova-expert done, thank you! |
This PR fixes issue #264 where PowerShell sensors and commands fail when users have custom profile scripts (e.g., Starship terminal prompt).
Problem
When executing PowerShell commands or scripts, HASS.Agent was not using the
-NoProfileflag. This caused custom profile scripts (likeMicrosoft.PowerShell_profile.ps1) to be loaded, which could:Solution
Added
-NoProfileflag to all PowerShell executions inPowershellManager.cs:GetProcessArgumentsmethod - Used byExecuteHeadlessandExecute:-NoProfile -File "{command}"-NoProfile -EncodedCommand {encodedCommand}ExecuteWithOutputmethod - Used by sensors for testing:-NoProfile & '{command}'-NoProfile & {{{command}}}The
-NoProfileflag tells PowerShell to skip loading any profile scripts, ensuring clean and predictable execution.Closes #264