diff --git a/src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs b/src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs index fee6ac69..25e4a5fa 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,8 @@ internal static bool ExecuteWithOutput(string command, TimeSpan timeout, out str WorkingDirectory = workingDir, StandardOutputEncoding = encoding, StandardErrorEncoding = encoding, - // set the right type of arguments - Arguments = isScript - ? $@"& '{command}'" - : $@"& {{{command}}}" + // set the right type of arguments, -NoProfile prevents custom profile scripts from interfering + Arguments = GetProcessArguments(command, "", isScript) }; using var process = new Process();