From c097d9642f5e74b726859bd859f69f41ad169782 Mon Sep 17 00:00:00 2001 From: Jordan Berger Date: Sat, 3 Jan 2026 06:31:21 -0700 Subject: [PATCH 1/2] Add -NoProfile flag to PowerShell executions --- .../HASS.Agent.Shared/Managers/PowershellManager.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs b/src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs index fee6ac69..9c06acf6 100644 --- a/src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs +++ b/src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs @@ -36,14 +36,14 @@ private static string GetProcessArguments(string command, string parameters, boo if (isScript) { return string.IsNullOrWhiteSpace(parameters) - ? $"-File \"{command}\"" - : $"-File \"{command}\" {parameters}"; + ? $"-NoProfile -File \"{command}\"" + : $"-NoProfile -File \"{command}\" {parameters}"; } else { //return $@"& {{{command}}}"; //NOTE: place to fix any potential future issues with "command part of the command" var encodedCommand = Convert.ToBase64String(Encoding.Unicode.GetBytes(command)); - return $"-EncodedCommand {encodedCommand}"; + return $"-NoProfile -EncodedCommand {encodedCommand}"; } } @@ -265,10 +265,10 @@ internal static bool ExecuteWithOutput(string command, TimeSpan timeout, out str WorkingDirectory = workingDir, StandardOutputEncoding = encoding, StandardErrorEncoding = encoding, - // set the right type of arguments + // set the right type of arguments, -NoProfile prevents custom profile scripts from interfering Arguments = isScript - ? $@"& '{command}'" - : $@"& {{{command}}}" + ? $@"-NoProfile & '{command}'" + : $@"-NoProfile & {{{command}}}" }; using var process = new Process(); From 172047a870adceebc96bbd9f18002f1c42a4f8ff Mon Sep 17 00:00:00 2001 From: AmonReviled Date: Tue, 10 Feb 2026 16:53:16 -0700 Subject: [PATCH 2/2] Use GetProcessArguments in ExecuteWithOutput for consistency and PS7+ compat --- .../HASS.Agent.Shared/Managers/PowershellManager.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs b/src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs index 9c06acf6..25e4a5fa 100644 --- a/src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs +++ b/src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs @@ -266,9 +266,7 @@ internal static bool ExecuteWithOutput(string command, TimeSpan timeout, out str StandardOutputEncoding = encoding, StandardErrorEncoding = encoding, // set the right type of arguments, -NoProfile prevents custom profile scripts from interfering - Arguments = isScript - ? $@"-NoProfile & '{command}'" - : $@"-NoProfile & {{{command}}}" + Arguments = GetProcessArguments(command, "", isScript) }; using var process = new Process();