diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs index ef8a815fdf3..3ed263eaed5 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/CombinePathCommand.cs @@ -3,6 +3,7 @@ --********************************************************************/ using System; +using System.Text; using System.Collections.ObjectModel; using System.Management.Automation; using Dbg = System.Management.Automation; @@ -32,7 +33,17 @@ public class JoinPathCommand : CoreCommandWithCredentialsBase [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true)] [AllowNull] [AllowEmptyString] - public string ChildPath { get; set; } = String.Empty; + public string ChildPath { get; set; } + + /// + /// Gets or sets additional childPaths to the command. + /// + + [Parameter(Position = 2, Mandatory = false, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = true)] + [AllowNull] + [AllowEmptyString] + [AllowEmptyCollection] + public string[] AdditionalChildPath { get; set; } = Utils.EmptyArray(); /// /// Determines if the path should be resolved after being joined @@ -55,6 +66,17 @@ protected override void ProcessRecord() Path != null, "Since Path is a mandatory parameter, paths should never be null"); + string combinedChildPath = ChildPath; + + // join the ChildPath elements + if (AdditionalChildPath != null) + { + foreach (string childPath in AdditionalChildPath) + { + combinedChildPath = SessionState.Path.Combine(combinedChildPath, childPath, CmdletProviderContext); + } + } + foreach (string path in Path) { // First join the path elements @@ -64,7 +86,7 @@ protected override void ProcessRecord() try { joinedPath = - SessionState.Path.Combine(path, ChildPath, CmdletProviderContext); + SessionState.Path.Combine(path, combinedChildPath, CmdletProviderContext); } catch (PSNotSupportedException notSupported) { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Join-Path.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Join-Path.Tests.ps1 index 9bd63888dff..d21e03369be 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Join-Path.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Join-Path.Tests.ps1 @@ -43,4 +43,9 @@ Describe "Join-Path cmdlet tests" -Tags "CI" { $result.Count | Should be 1 $result | Should BeExactly ("Env:"+$SepChar+"foo") } + It "should be able to join multiple child paths passed by position with remaining arguments" { + $result = Join-Path one two three four five + $result.Count | Should Be 1 + $result | Should BeExactly "one${sepChar}two${sepChar}three${sepChar}four${sepChar}five" + } }