Skip to content

Instantly share code, notes, and snippets.

@chriskuech
Created June 12, 2019 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriskuech/f51051d0b55a3c15ff171756a01c9253 to your computer and use it in GitHub Desktop.
Save chriskuech/f51051d0b55a3c15ff171756a01c9253 to your computer and use it in GitHub Desktop.
function Invoke-Requirement {
[CmdletBinding()]
Param(
[Parameter(Mandatory, ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[Requirement[]]$Requirement
)
process {
$result = &$_.Test
if (-not $result) {
&$_.Set | Out-Null
$result = &$_.Test
if (-not $result) {
throw "Validation failed for '$($_.Name)'"
}
}
}
}
$requirements | Invoke-Requirement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment