If you have the arrays:
$requiredFruit= @("apple","pear","nectarine","grape")
$someFruit= @("apple","banana","pear","nectarine","orange","grape")
$moreFruit= @("apple","banana","nectarine","grape")
You can get a boolean result with:
'Check $someFruit for $requiredFruit'
-not @($requiredFruit| where {$someFruit -notcontains $_}).Count
'Check $moreFruit for $requiredFruit'
-not @($requiredFruit| where {$moreFruit -notcontains $_}).Count
Using the count of an array protects against a single value not matching that evaluates as False. For example:
# Incorrect result
-not (0| where {(1,2) -notcontains $_})
# Correct result
-not @(0| where {(1,2) -notcontains $_}).Count
With PowerShell v3, you can use select -first 1
to stop the pipeline when the first mismatch is found (in v2 select -first 1
allows only one object through, but previous elements of the pipeline continue to process).
-not @($requiredFruit| where {$moreFruit -notcontains $_}| select -first 1).Count