Forum Discussion
Counting Matches in an Array
- Dec 09, 2021
Hello Rich89,
Excerpt from -match operator documentation:
...When the input is a collection of values, the operators return any matching members. If there are no matches in a collection, the operators return an empty array.
So in your specific use case:
$howMany = $files.hash -match $file.hash
If there are identical files in $files.hash collection, your $howMany variable will contain collection of matching hashes.(in this case there will be at least 2 members).
If there are no duplicates of specific file hash your $howMany variable will contain empty array.
Reference: about_Comparison_Operators.MatchingOperators
Hope that helps.
Hello Rich89,
Excerpt from -match operator documentation:
...When the input is a collection of values, the operators return any matching members. If there are no matches in a collection, the operators return an empty array.
So in your specific use case:
$howMany = $files.hash -match $file.hash
If there are identical files in $files.hash collection, your $howMany variable will contain collection of matching hashes.(in this case there will be at least 2 members).
If there are no duplicates of specific file hash your $howMany variable will contain empty array.
Reference: about_Comparison_Operators.MatchingOperators
Hope that helps.
- AndySvintsDec 10, 2021Steel ContributorOops, link has been updated.
Thank you.