I need to determine if an array of PSCustomObject
s contains an item with its Title
property matching a value. I need a Boolean value for use with Pester assertions:
$Items -<function> $Name | Should Be $True
Assuming:
$Items = @() $Items += [PsCustomObject]@{Title='foo';Url='http://f.io'} $Items += [PsCustomObject]@{Title='bar';Url='http://b.io'}
Contains
does not work:
PS> $Items -contains 'foo' False
Match
returns the matching instance, but it is not a Boolean:
PS> $Items -match 'foo' Title Url ----- --- foo http://f.io
I suppose I could:
($Items -Match $Name).Count | Should Be 1
Is there a better option?
Use:
$Items.Title -contains 'foo'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With