Skip to content

Instantly share code, notes, and snippets.

@nicolonsky
Created January 8, 2019 06:03
Show Gist options
  • Save nicolonsky/9c09096dd91ceb7a8fa43ab5cf4c3740 to your computer and use it in GitHub Desktop.
Save nicolonsky/9c09096dd91ceb7a8fa43ab5cf4c3740 to your computer and use it in GitHub Desktop.
[ValidateScript({
$requiredProperties=@("Property1","Property2","Property3", "Property4")
$members=Get-Member -InputObject $_ -MemberType NoteProperty
$missingProperties=Compare-Object -ReferenceObject $requiredProperties -DifferenceObject $members.Name -PassThru -ErrorAction SilentlyContinue
if (-not($missingProperties)){
$true
}else{
$missingProperties | ForEach-Object {
Throw [System.Management.Automation.ValidationMetadataException] "Property: '$_' missing"
}
}
})]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment