Private/Test-VcListObject.ps1
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
function Test-VcListObject { <# .SYNOPSIS Returns True if running on PowerShell Core. .NOTES Author: Aaron Parker Twitter: @stealthpuppy .PARAMETER InputObject The InputObject to validate RequiredProperties against .PARAMETER Version An array of the require properties to validate against the InputObject #> [CmdletBinding()] [OutputType([System.Boolean])] param ( [Parameter( Mandatory = $true, Position = 0, ValueFromPipeline = $true, HelpMessage = "Pass a VcList object from Get-VcList.")] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSObject] $VcList, [Parameter(Position = 1)] [System.String[]] $RequiredProperties = @("Architecture", "Install", "Name", "ProductCode", ` "Release", "SilentInstall", "SilentUninstall", "UninstallKey", "URI", "URL", "Version", "Path") ) process { foreach ($Item in $VcList) { $Members = Get-Member -InputObject $Item -MemberType "NoteProperty" $params = @{ ReferenceObject = $RequiredProperties DifferenceObject = $Members.Name PassThru = $true ErrorAction = "Stop" } $MissingProperties = Compare-Object @params if (-not($missingProperties)) { $Result = $true } else { $MissingProperties | ForEach-Object { throw [System.Management.Automation.ValidationMetadataException] "Property: '$_' missing." } } $Item.PSObject.Properties | ForEach-Object { if (([System.String]::IsNullOrEmpty($_.Value))) { throw [System.Management.Automation.ValidationMetadataException] "Property '$($_.Name)' is null or empty." } } } # Return true if all is good with the object return $Result } } |