I've been trying to write a script and in a section of it, I need to compare names of users to a explicit list. So Powershell is presented with the names of all users on a specific system and I need to find any users that start with a certain string. All accounts that need to be counted start with "xxx" or "yyy" but have varying length.
Now this bit is fine and I could use something like the below line to count these.
Where-Object {$_.name -Match "xxx"} | Select Name | Measure
But I don't want to have multiple lines doing the same thing so comparing them to items in an array would be great. For this, I have the below lines.
$valuesToMatch = @("xxx""yyy" ) Where-Object {$valuesToMatch -Match $_.name}
But when I am using the method above (I have, of course, missed out various lines for sake of simplicity) it only counts it if it is an exact match. A.K.A. if the list of users was xxx, xxxbob this would only match with xxx and not xxxbob.
With the first line it matched to include but when checking from the array it has to be exact, what is the cause / workaround of this?