I have an array $array with many elements, an example looks like this:
ProfileID         : 100
UID               : 17
Name              : SharePoint
Description       : SharePoint Server Description
Now I am trying to filter by Name property, string to match is:
$string
SharePoint Policy Assignment
I have tried:
$array | Where-Object {$_.Name -like "$string"}
no match
$array | Where-Object {$_.Name -like "$string*"}
no match
$array | Where-Object {$_.Name -match "$string"}
no match
Is this possible using PowerShell? What am I missing?
 
                        
The
-likeoperator in PowerShell is used for a wildcard match, so you need to use the wildcard character, the asterisk,*.Imagine this scenario, where I'm trying to match a particular Windows Service.
To use the
-Likeoperator to get a match, I have to provide a Wildcard Character, like this.Try your operation using a WildCard, and I bet it will work :)
One other thing I noted, your
$stringis equal toSharePoint Policy Assignment, but the column you're comparing on of.Nameis justSharePoint.