This might seem like a very stupid question, but I can't seem to figure it out. How can you put a relationship between values of an object?
I think the code will speak for itself:
$Collection = ("Fruit","Banana"),("Vegetables","Aubergine"),("Fruit","Appel"),("Vegetables","Courgette") |
ForEach-Object {
[PSCustomObject]@{
'Type'=$_[0]
'Content'=$_[1]
}
}
if ($Collection.Type -contains "Fruit" -and $Collection.Content -contains "Courgette") {
Write-Host "We DID find a match" -ForegroundColor Green
}
else {
Write-Host "We didn't find a match" -ForegroundColor Red
}
<# Result
Fruit + Banana = "We DID find a match"
Fruit + Courgette= "We DID find a match"
#>
How is it possible to only have a match when the pair matches? For example I would like it match in the case of Fruit + Banana but not in case of Fruit + Courgette.
I'm sorry if this sounds silly.. Thank you for your help.
$Collection | ?{$_.Type -eq "Fruit" -and $_.Content -eq "Banana"}??