functions/string/Add-PSUString.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function Add-PSUString
{
<#
    .SYNOPSIS
        Makes it easy to add content to a string at pipeline.
     
    .DESCRIPTION
        Makes it easy to add content to a string at pipeline.
     
    .PARAMETER InputString
        The string(s) to add content to
     
    .PARAMETER Before
        What is prepended to the input string.
     
    .PARAMETER After
        What is appended to the input string
     
    .EXAMPLE
        1..10 | Add-PSUString "srv-ctx" "-dev"
     
        Returns a set of strings from 'srv-ctx1-dev' through 'srv-ctx10-dev'
#>

    [OutputType([System.String])]
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipeline = $true)]
        [string[]]
        $InputString,
        
        [Parameter(Position = 0)]
        [string]
        $Before = "",
        
        [Parameter(Position = 1)]
        [string]
        $After = ""
    )
    
    begin { }
    process
    {
        foreach ($line in $InputString)
        {
            "$($Before)$($line)$($After)"
        }
    }
    end { }
}
Import-PSUAlias -Name add -Command Add-PSUString
Import-PSUAlias -Name wrap -Command Add-PSUString