Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs (C#)

Code before:
#if UNIX
            const string sshCommand = "ssh";
#else
            const string sshCommand = "ssh.exe";
#endif
            var context = Runspaces.LocalPipeline.GetExecutionContextFromTLS();
            if (context != null)
            {
                var cmdInfo = CommandDiscovery.LookupCommandInfo(
                    sshCommand,
                    CommandTypes.Application,
                    SearchResolutionOptions.None,
                    CommandOrigin.Internal,
                    context) as ApplicationInfo;
                if (cmdInfo != null)
                {
                    filePath = cmdInfo.Path;
                }
            }
            else
            {
                // A Runspace may not be present in the TLS in SDK hosted apps
                // or if running in another thread without a Runspace. While
                // ProcessStartInfo can lookup the full path in PATH, we set
                // the cwd to the parent directory of the found executable so
                // we do a manual lookup here.
                string[] entries = Environment.GetEnvironmentVariable("PATH")?.Split(
                    Path.PathSeparator,
                    StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) ?? [];
                foreach (var path in entries)
                {
                    if (!Path.IsPathFullyQualified(path))
                    {
                        continue;
                    }

                    var sshCommandPath = Path.Combine(path, sshCommand);
                    if (File.Exists(sshCommandPath))
                    {
                        filePath = sshCommandPath;
                        break;
                    }
                }
            }
            
            if (string.IsNullOrEmpty(filePath))
            {
                throw new CommandNotFoundException(
                    sshCommand,
                    null,
                    "CommandNotFoundException",

Review comment (suggestion):
I don't see where we _explicitly_ set the cwd. So we could exclude manual lookup and do here simply:
```c#
    filePath = sshCommand;
```

Code after:
#if UNIX
            const string sshCommand = "ssh";
#else
            const string sshCommand = "ssh.exe";
#endif
            var context = Runspaces.LocalPipeline.GetExecutionContextFromTLS();
            if (context != null)
            {
                var cmdInfo = CommandDiscovery.LookupCommandInfo(
                    sshCommand,
                    CommandTypes.Application,
                    SearchResolutionOptions.None,
                    CommandOrigin.Internal,
                    context) as ApplicationInfo;

                if (cmdInfo != null)
                {
                    filePath = cmdInfo.Path;
                }
            }
            else
            {
                // A Runspace may not be present in the TLS in SDK hosted apps
                // or if running in another thread without a Runspace. While
                // 'ProcessStartInfo' can lookup the full path in PATH, it searches
                // the process' working directory first. 'LookupCommandInfo' does
                // not search the process' working directory and we want to keep that
                // behavior. We also get the parent dir of the full path to set as the
                // new WorkingDirectory. So, we do a manual lookup here only in PATH.
                string[] entries = Environment.GetEnvironmentVariable("PATH")?.Split(
                    Path.PathSeparator,
                    StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) ?? [];
                foreach (var path in entries)
                {
                    if (!Path.IsPathFullyQualified(path))
                    {
                        continue;
                    }

                    var sshCommandPath = Path.Combine(path, sshCommand);
                    if (File.Exists(sshCommandPath))
                    {
                        filePath = sshCommandPath;
                        break;
                    }
                }
            }
            
            if (string.IsNullOrEmpty(filePath))
            {
                throw new CommandNotFoundException(