@@ -534,20 +534,9 @@ await Task.Factory.StartNew<IEnumerable<TResult>>(
534
534
535
535
if ( this . powerShell . HadErrors )
536
536
{
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
-
549
537
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 ) ) ;
551
540
552
541
int i = 1 ;
553
542
foreach ( var error in this . powerShell . Streams . Error )
@@ -1433,7 +1422,20 @@ private static string GetStringForPSCommand(PSCommand psCommand)
1433
1422
foreach ( var command in psCommand . Commands )
1434
1423
{
1435
1424
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 ( ) ;
1437
1439
}
1438
1440
1439
1441
return stringBuilder . ToString ( ) ;
0 commit comments