-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAnyValidObject.ps1
More file actions
27 lines (23 loc) · 680 Bytes
/
AnyValidObject.ps1
File metadata and controls
27 lines (23 loc) · 680 Bytes
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
<#
.SYNOPSIS
Determines if any validation passes, given an object.
.DESCRIPTION
Determines if any of the `[ValidateScript]` attributes on a `[ScriptBlock]` passes, given an input.
Any input considered valid by a `[ValidateScript]` will be returned.
.EXAMPLE
{
[ValidateScript({$_ -like "a*" })]
param()
}.AnyValidObject("a")
#>
param()
$allArgs = $args | & { process { $_ }}
, @(foreach ($attr in $this.Attributes) {
if (-not $attr.Validate) { continue }
if ($attr.Validate -isnot [ValidateScript]) { continue }
foreach ($arg in $allArgs) {
if ($attr.Validate($arg)) {
$arg
}
}
})