another PowerShell noob question.
I have an array of strings that contains the names of businesses and I am writing a script that iterates through the folders of a directory and compares the folder names to the names contained in the array. When I find a match I need to get the array index where the match was found. I've done this successfully for exact matches using the following code:
foreach($file in Get-ChildItem $targetDirectory)
{
if($businesses -like "$file*")
{
$myIndex = [array]::IndexOf($businesses, [string]$file)
}
}
The reason I use -like "$file*" is because sometimes the name of the business has "LLC" or "INC" or something like that, which occasionally wasn't included when we named the folders(and vice versa). I would like to modify my $myIndex line to find these indexes as well.
I'm trying to use
$myIndex = [array]::FindIndex($Merchant, {args[0] -like "$file*"})
But I'm getting the error
Cannot find an overload for "FindIndex" and the argument count: "2".
I've tried casting the second argument using [Predicate[string]]{args[0] -like "$file*"} but get the same result. I've read the documentation for the method but one of my basic problems is I don't understand the System.Predicate type. I'm not even sure if I'm writing it properly; I found an example that was similar but used [int] instead. Maybe I'm going about it all wrong but I feel like I'm close and just can't find the missing piece of the puzzle anywhere.
Thanks in advance for any help.