diff --git a/src/PowerShellEditorServices/Session/PowerShellContext.cs b/src/PowerShellEditorServices/Session/PowerShellContext.cs index 47c11272b..f8d6e69a3 100644 --- a/src/PowerShellEditorServices/Session/PowerShellContext.cs +++ b/src/PowerShellEditorServices/Session/PowerShellContext.cs @@ -535,7 +535,7 @@ await Task.Factory.StartNew>( if (this.powerShell.HadErrors) { var strBld = new StringBuilder(1024); - strBld.AppendFormat("Execution of the following command(s) completed with errors:\r\n\r\n{0}\r\n", + strBld.AppendFormat("Execution of the following command(s) completed with errors:\r\n\r\n{0}\r\n", GetStringForPSCommand(psCommand)); int i = 1; @@ -838,15 +838,14 @@ await this.ExecuteCommand( Collection results = pipeline.Invoke(); - if (results.Count == 0) + if (results.Count == 0 || results.FirstOrDefault() == null) { return defaultValue; } if (typeof(TResult) != typeof(PSObject)) { - return - results + return results .Select(pso => pso.BaseObject) .OfType() .FirstOrDefault();