-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathFormat-ReverseString.ps1
65 lines (56 loc) · 1.73 KB
/
Format-ReverseString.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Function Format-ReverseString {
<#
.SYNOPSIS
To reverse a string, or an array of strings
.DESCRIPTION
To reverse a string, or an array of strings. Function aliased to 'Reverse'
.PARAMETER String
The string you wish to be reversed. Can be a string or an array of strings.
Can be passed from the pipeline
.PARAMETER IncludeInput
Switch to include the input along with the output. Aliased to 'IncludeOriginal' for
backward compatibility
.EXAMPLE
Format-ReverseString -String 'Hello'
olleH
.EXAMPLE
Format-ReverseString -String 'Hello' -IncludeInput
Original Reverse
-------- -------
Hello olleH
.EXAMPLE
'758', '129' | Format-ReverseString -IncludeInput
Original Reverse
-------- -------
758 857
129 921
#>
[CmdletBinding(ConfirmImpact='None')]
[alias('ReverseString')] #FunctionAlias
[OutputType('string')]
param(
[Parameter(Mandatory, HelpMessage='Enter a string you wish to be reversed',Position=0,ValueFromPipeline)]
[string[]] $String,
[Alias('IncludeOriginal')]
[switch] $IncludeInput
)
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
}
process {
foreach ($currentString in $String) {
$ReturnVal = [string]::Join('', $currentString[($currentString.Length-1)..0])
if ($IncludeInput) {
New-Object -TypeName 'psobject' -Property ([ordered] @{
Original = $currentString
Reverse = $ReturnVal
})
} else {
write-output -InputObject $ReturnVal
}
}
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
}