Forum Discussion
Rich89
Dec 09, 2021Brass Contributor
Counting Matches in an Array
I am hoping someone can point me to documentation or explain how/why this is working in a script that I've written. What I needed to do is make PowerShell create a report of any duplicated file in a...
- 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.
Rich89
Dec 09, 2021Brass Contributor
That perfectly answers my question thank you. Your link appears to take me to a different page than intended I think, but your excerpt explains it. Thank you!
AndySvints
Dec 10, 2021Steel Contributor
Oops, link has been updated.
Thank you.
Thank you.