-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathFormat-RandomCase.ps1
70 lines (62 loc) · 1.91 KB
/
Format-RandomCase.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
66
67
68
69
70
function Format-RandomCase {
<#
.SYNOPSIS
Formats a string character by character randomly into upper or lower case.
.DESCRIPTION
Formats a string character by character randomly into upper or lower case.
.PARAMETER String
A [string[]] that you want formatted randomly into upper or lower case
.PARAMETER IncludeInput
Switch that will display input parameters in the output
.EXAMPLE
Format-RandomCase -String 'HELLO WORLD IT IS ME!'
Example return
HelLo worlD It is me!
.EXAMPLE
Format-RandomCase -String HELLO, WORLD, IT, IS, ME -IncludeInput
Example return
Original Return
-------- ------
HELLO hELLo
WORLD wORLd
IT It
IS is
ME ME
.OUTPUTS
[string[]]
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','')]
param (
[parameter(ValueFromPipeline)]
[string[]] $String,
[switch] $IncludeInput
)
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
}
process {
foreach ($CurrentString in $String) {
$CharArray = [char[]] $CurrentString
$CharArray | ForEach-Object -Begin { $ReturnVal = '' } -Process {
$Random = 0,1 | Get-Random
if ($Random -eq 0) {
$ReturnVal += ([string] $_).ToLower()
} else {
$ReturnVal += ([string] $_).ToUpper()
}
}
if ($IncludeInput) {
New-Object -TypeName psobject -Property ([ordered] @{
Original = $CurrentString
Return = $ReturnVal
})
} else {
Write-Output -InputObject $ReturnVal
}
}
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
} # EndFunction Format-RandomCase