/
Apply-CustomLogic.ps1
45 lines (37 loc) · 991 Bytes
/
Apply-CustomLogic.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
function Apply-CustomLogic($condition,$V1,$V2){
$condition = $condition.ToLower()
switch($condition){
"like" {
$string = '$V1 -like "*$V2*"'
}
"is" {
$string = '$V1 -eq $V2'
}
"isnot" {
$string = '$V1 -ne $V2'
}
"startswith" {
$string = '$V1.StartsWith($V2)'
}
"notstartswith" {
$string = '!($V1.StartsWith($V2))'
}
"endswith" {
$string = '$V1.EndsWith($V2)'
}
"notendswith" {
$string = '!($V1.EndsWith($V2))'
}
}
if(
$string -and
($sb = [scriptblock]::Create($string)) -and
($result = $sb.Invoke())
){
Write-Verbose("Using Logic `"$condition`" on `"$V1`" versus `"$V2`", Result is: `"$result`"<br/>")
return $result
}else{
Write-Verbose("Error, executing failed.")
return $false
}
}