Created
January 8, 2019 06:03
-
-
Save nicolonsky/9c09096dd91ceb7a8fa43ab5cf4c3740 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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