- function Test-Conditions{
- [OutputType([bool])]
- [CmdletBinding()]
- param([scriptblock[]]$Logic)
- DynamicParam{
- $Attribute=[System.Management.Automation.ParameterAttribute]::new()
- $Attribute.Mandatory=$false
- $Attribute.ValueFromPipeline=$true
- $AttributeCollection=[System.Collections.ObjectModel.Collection[System.Attribute]]::new()
- $AttributeCollection.Add($Attribute)
- $InputObject=[System.Management.Automation.RuntimeDefinedParameter]::new('InputObject',[object],$AttributeCollection)
- $paramDictionary=[System.Management.Automation.RuntimeDefinedParameterDictionary]::new()
- if($Logic -ne $null){$Attribute.DontShow=1}
- $paramDictionary.Add('InputObject',$InputObject)
- return $paramDictionary
- }
- begin{[System.Collections.Generic.Dictionary[scriptblock,bool]]$dic=@{}}
- process{
- for([int]$i=0;$i -lt $Logic.Count;$i++){
- if($Logic[$i].Invoke()){
- $dic[$Logic[$i]]=$Logic[$i].Invoke()
- }
- }
- }
- end{$Logic.Count -eq $dic.Count}
- }
- # Test
- $a=10
- 100,30|Test-Conditions {$_ -eq 100},{$a -eq 10}
复制代码 全部满足即返回true |