diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/join-string.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/join-string.cs
index 80da5e379..62282a8da 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/join-string.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/join-string.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
@@ -90,7 +90,7 @@ namespace Microsoft.PowerShell.Commands.Utility
/// Gets or sets the input object to join into text.
///
[Parameter(ValueFromPipeline = true)]
- public PSObject InputObject { get; set; }
+ public PSObject[] InputObject { get; set; }
///
protected override void BeginProcessing()
@@ -106,40 +106,46 @@ namespace Microsoft.PowerShell.Commands.Utility
///
protected override void ProcessRecord()
{
- if (InputObject != null && InputObject != AutomationNull.Value)
+ if (InputObject != null)
{
- var inputValue = Property == null
- ? InputObject
- : Property.GetValues(InputObject, false, true).FirstOrDefault()?.Result;
+ foreach (PSObject inputObject in InputObject)
+ {
+ if (inputObject != null && inputObject != AutomationNull.Value)
+ {
+ var inputValue = Property == null
+ ? inputObject
+ : Property.GetValues(inputObject, false, true).FirstOrDefault()?.Result;
- // conversion to string always succeeds.
- if (!LanguagePrimitives.TryConvertTo(inputValue, _cultureInfo, out var stringValue))
- {
- throw new PSInvalidCastException("InvalidCastFromAnyTypeToString", ExtendedTypeSystem.InvalidCastCannotRetrieveString, null);
- }
+ // conversion to string always succeeds.
+ if (!LanguagePrimitives.TryConvertTo(inputValue, _cultureInfo, out var stringValue))
+ {
+ throw new PSInvalidCastException("InvalidCastFromAnyTypeToString", ExtendedTypeSystem.InvalidCastCannotRetrieveString, null);
+ }
- if (_firstInputObject)
- {
- _firstInputObject = false;
- }
- else
- {
- _outputBuilder.Append(Separator);
- }
+ if (_firstInputObject)
+ {
+ _firstInputObject = false;
+ }
+ else
+ {
+ _outputBuilder.Append(Separator);
+ }
- if (_quoteChar != char.MinValue)
- {
- _outputBuilder.Append(_quoteChar);
- _outputBuilder.Append(stringValue);
- _outputBuilder.Append(_quoteChar);
- }
- else if (string.IsNullOrEmpty(FormatString))
- {
- _outputBuilder.Append(stringValue);
- }
- else
- {
- _outputBuilder.AppendFormat(_cultureInfo, FormatString, inputValue);
+ if (_quoteChar != char.MinValue)
+ {
+ _outputBuilder.Append(_quoteChar);
+ _outputBuilder.Append(stringValue);
+ _outputBuilder.Append(_quoteChar);
+ }
+ else if (string.IsNullOrEmpty(FormatString))
+ {
+ _outputBuilder.Append(stringValue);
+ }
+ else
+ {
+ _outputBuilder.AppendFormat(_cultureInfo, FormatString, inputValue);
+ }
+ }
}
}
}
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Join-String.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Join-String.Tests.ps1
index f4dae19a1..20829d621 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Join-String.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Join-String.Tests.ps1
@@ -11,6 +11,12 @@ Describe "Join-String" -Tags "CI" {
{ Join-String -InputObject $testObject } | Should -Not -Throw
}
+ It "'Input | Join-String' should be equal to 'Join-String -InputObject Input'" {
+ $result1 = $testObject | Join-String
+ $result2 = Join-String -InputObject $testObject
+ $result1 | Should -BeExactly $result2
+ }
+
It "Should return a single string" {
$actual = $testObject | Join-String