-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps-wad.psm1
179 lines (123 loc) · 3.95 KB
/
ps-wad.psm1
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
function Get-MatchAll{
<#
.SYNOPSIS
Returns $true if match operator returns $true on all members of the array when compared to the input string.
.DESCRIPTION
Returns $true if match operator returns $true on all members of the array when compared to the input string.
Interally runs a match operator against each member of an array. Only if all results are $true, will this function also return $true.
Optionally enable case sensitivity with the $CaseSensitivity flag.
.PARAMETER Array
Input array of strings or whatever you want.
.PARAMETER String
Input string to be compared to each member of the array.
.PARAMETER CaseSensitive
Boolean. Switches between match and cmatch internally. Defaults to $false.
.INPUTS
Don't do this. It's for use in "if" statements primarily.
.OUTPUTS
Boolean $true or $false.
.EXAMPLE
PS> Get-MatchAll -Array @("Word","Story","Floor") -String "or"
True
#>
param(
$Array,
$String,
[bool]$CaseSensitive = $false
)
$match = $true
foreach($thing in $array)
{
if($CaseSensitive)
{
if($thing -cnotmatch $string){$match = $false}
}
else
{
if($thing -notmatch $String){$match = $false}
}
}
return $match
}
function Get-MatchNone{
<#
.SYNOPSIS
Returns $true if match operator returns $false on all members of the array when compared to the input string.
.DESCRIPTION
Returns $true if match operator returns $false on all members of the array when compared to the input string.
Interally runs a match operator against each member of an array. Only if all results are $false, will this function return $true.
Optionally enable case sensitivity with the $CaseSensitivity flag.
.PARAMETER Array
Input array of strings or whatever you want.
.PARAMETER String
Input string to be compared to each member of the array.
.PARAMETER CaseSensitive
Boolean. Switches between match and cmatch internally. Defaults to $false.
.INPUTS
Don't do this. It's for use in "if" statements primarily.
.OUTPUTS
Boolean $true or $false.
.EXAMPLE
PS> Get-MatchNone -Array @("Word","Story","Floor") -String "an"
True
#>
param(
$Array,
$String,
[bool]$CaseSensitive = $false
)
$match = $true
foreach($thing in $array)
{
if($CaseSensitive)
{
if($thing -cmatch $String){$match = $false}
}
else
{
if($thing -match $String){$match = $false}
}
}
return $match
}
function Get-MatchAny{
<#
.SYNOPSIS
Returns $true if match operator returns $true on any members of the array when compared to the input string.
.DESCRIPTION
Returns $true if match operator returns $true on any members of the array when compared to the input string.
Interally runs a match operator against each member of an array. If any of the results are $true, this function will return $true.
Optionally enable case sensitivity with the $CaseSensitivity flag.
.PARAMETER Array
Input array of strings or whatever you want.
.PARAMETER String
Input string to be compared to each member of the array.
.PARAMETER CaseSensitive
Boolean. Switches between match and cmatch internally. Defaults to $false.
.INPUTS
Don't do this. It's for use in "if" statements primarily.
.OUTPUTS
Boolean $true or $false.
.EXAMPLE
PS> Get-MatchAny -Array @("Word","Story","Floor") -String "sto"
True
#>
param(
$Array,
$String,
[bool]$CaseSensitive = $false
)
$match = $false
foreach($thing in $Array)
{
if($CaseSensitive)
{
if($thing -cmatch $String){$match = $true}
}
else
{
if($thing -match $String){$match = $true}
}
}
return $match
}