Skip to content

Commit 8c49158

Browse files
committed
Add a new Test-Validation cmdlet returning a boolean value instead of error messages
1 parent 75c492a commit 8c49158

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

Sources/Test-Validation.ps1

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
.INPUTS
77
The object to validate.
88
.OUTPUTS
9-
The validation errors, if any.
9+
`$true` if the validated object is valid, otherwise `$false`.
1010
#>
1111
function Test-Validation {
1212
[CmdletBinding()]
13-
[OutputType([hashtable])]
13+
[OutputType([bool])]
1414
param (
1515
# The object to validate.
1616
[Parameter(Mandatory, Position = 1, ValueFromPipeline)]
@@ -22,18 +22,13 @@ function Test-Validation {
2222
)
2323

2424
process {
25-
$errors = @{}
26-
2725
foreach ($property in $RuleSet.Keys) {
28-
foreach ($item in @($RuleSet[$property])) {
29-
$validator = [Validator] $item
30-
if (-not $validator.IsValid($Object.$property)) {
31-
$errors[$property] = $validator.Reason
32-
break
33-
}
26+
foreach ($rule in @($RuleSet[$property])) {
27+
$validator = [Validator] $rule
28+
if (-not $validator.IsValid($Object.$property)) { return $false }
3429
}
3530
}
3631

37-
$errors
32+
$true
3833
}
3934
}

0 commit comments

Comments
 (0)