diff --git a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs
index 72b2f7c5342..3109cc966b6 100644
--- a/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs
+++ b/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs
@@ -2182,7 +2182,7 @@ internal static int StartSSHProcess(
string filename = startInfo.FileName;
string[] argv = ParseArgv(startInfo);
- string[] envp = new string[0];
+ string[] envp = CopyEnvVariables(startInfo);
string cwd = !string.IsNullOrWhiteSpace(startInfo.WorkingDirectory) ? startInfo.WorkingDirectory : null;
// Invoke the shim fork/execve routine. It will create pipes for all requested
@@ -2239,6 +2239,20 @@ private static FileStream OpenStream(int fd, FileAccess access)
access, StreamBufferSize, isAsync: false);
}
+ /// Copies environment variables from ProcessStartInfo
+ /// ProcessStartInfo
+ /// String array of environment key/value pairs
+ private static string[] CopyEnvVariables(ProcessStartInfo psi)
+ {
+ var envp = new string[psi.Environment.Count];
+ int index = 0;
+ foreach (var pair in psi.Environment)
+ {
+ envp[index++] = pair.Key + "=" + pair.Value;
+ }
+ return envp;
+ }
+
/// Converts the filename and arguments information from a ProcessStartInfo into an argv array.
/// The ProcessStartInfo.
/// The argv array.