Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/HASS.Agent/HASS.Agent.Shared/Managers/PowershellManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
}

Expand Down Expand Up @@ -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();
Expand Down