Join-String.ps1
<#PSScriptInfo
.VERSION 1.2.1 .GUID e76c02b2-9bba-4f5f-8f00-4016d954ce4e .AUTHOR saw-friendship .COMPANYNAME .COPYRIGHT .TAGS Join String Pipeline .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION Join String from Array .EXAMPLE Join-String (Get-Process | select -f 3) -Property id -Separator ';' 5892;18344;4992 .EXAMPLE Get-Process | select -f 3 | Join-String -Property id -Separator ';' 5892;18344;4992 .EXAMPLE Join-String @(1..3) -Separator ';' 1;2;3 .EXAMPLE 1..3 | Join-String -Separator ';' 1;2;3 .EXAMPLE 1..3 | Join-String -Separator ',' -SingleQuote '1','2','3' .EXAMPLE Get-Process | select -l 3 | Join-String -Property id -Separator ';' -SingleQuote -OutputPrefix '"' -OutputSuffix '"' "'11384';'15324';'13624'" #> [CmdletBinding()] [Alias('join')] param( [Parameter(Mandatory=$true,ValueFromPipeline=$true)][System.Object[]]$InputObject ,[String]$Property ,[Parameter(Mandatory=$false)][alias('Separator')][String]$Delimiter = '' ,[Parameter(Mandatory=$false)][alias('OutputPrefix')][String]$Prefix = '' ,[Parameter(Mandatory=$false)][alias('OutputSuffix')][String]$Suffix = '' ,[Switch]$SingleQuote ,[Switch]$DoubleQuote ) Begin { [string]$Quote = if ($SingleQuote) {"'"} elseif ($DoubleQuote) {'"'} else {''} $StringArray = New-Object -TypeName 'System.Collections.Generic.List[System.String]' } Process { $InputObject | % { if ($Property) { $String = $Quote + ($_.psobject.Properties[$Property].Value -as [string]) + $Quote } else { $String = $Quote + ($_ -as [string]) + $Quote } [void]$StringArray.Add($String) } } End { $Prefix + ($StringArray -join $Delimiter) + $Suffix } |