@@ -534,20 +534,9 @@ await Task.Factory.StartNew<IEnumerable<TResult>>(
534534
535535 if ( this . powerShell . HadErrors )
536536 {
537- // Get the command/params that we were trying execute as a string in order to log it
538- string commandText = "" ;
539- foreach ( var cmd in psCommand . Commands )
540- {
541- commandText += cmd . CommandText ;
542- foreach ( var param in cmd . Parameters )
543- {
544- commandText += $ " -{ param . Name } { param . Value } ";
545- }
546- commandText += ";" ;
547- }
548-
549537 var strBld = new StringBuilder ( 1024 ) ;
550- strBld . Append ( $ "Execution of command '{ commandText } ' completed with errors:\r \n \r \n ") ;
538+ strBld . AppendFormat ( "Execution of the following command(s) completed with errors:\r \n \r \n {0}\r \n " ,
539+ GetStringForPSCommand ( psCommand ) ) ;
551540
552541 int i = 1 ;
553542 foreach ( var error in this . powerShell . Streams . Error )
@@ -1433,7 +1422,20 @@ private static string GetStringForPSCommand(PSCommand psCommand)
14331422 foreach ( var command in psCommand . Commands )
14341423 {
14351424 stringBuilder . Append ( " " ) ;
1436- stringBuilder . AppendLine ( command . ToString ( ) ) ;
1425+ stringBuilder . Append ( command . CommandText ) ;
1426+ foreach ( var param in command . Parameters )
1427+ {
1428+ if ( param . Name != null )
1429+ {
1430+ stringBuilder . Append ( $ " -{ param . Name } { param . Value } ") ;
1431+ }
1432+ else
1433+ {
1434+ stringBuilder . Append ( $ " { param . Value } ") ;
1435+ }
1436+ }
1437+
1438+ stringBuilder . AppendLine ( ) ;
14371439 }
14381440
14391441 return stringBuilder . ToString ( ) ;
0 commit comments