Join-Strings.psm1
<#
.SYNOPSIS Joins provided strings into a single string, similar to -join .DESCRIPTION Joins an array or pipeline of strings into a singular string, optionally using a provided delimiter. .EXAMPLE PS C:\> "String1", "OtherString" | Join-Strings "::" String1::OtherString PS C:\> $StringArray | Join-Strings "," .INPUTS Join-Strings accepts pipeline input as a collection of strings. .OUTPUTS Outputs a single string containing all previous strings joined together, including delimiter if specified. #> function Join-Strings { [CmdletBinding()] [Alias('js')] param( [Parameter(Position = 0, Mandatory, ValueFromPipeline)] [Alias('InputString', 'Strings')] [ValidateNotNull()] [string[]] $InputObject, [Parameter(Position = 1)] [Alias('JoinCharacter')] [ValidateNotNullOrEmpty()] [string] $Delimeter ) begin { $List = New-Object -TypeName 'System.Collections.Generic.List[string]' } process { $InputObject | ForEach-Object { [void]$List.Add($_) } } end { if ($PSBoundParameters.ContainsKey('Delimeter')) { Write-Output $List -join $Delimeter } else { Write-Output $List -join } } } |