Reputation: 1342
I want filter a list of objects by property "innerText". But I need to do some preparations. Why furhter code doesn't works? It returns all objects.
function enc[[string]$inp]
{
return [System.Text.Encoding]::GetEncoding("windows-1251").GetString([System.Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes($inp))
}
$req.Links | Where-Object { enc($_.innerText) -eq "my string"} | fl
What I'm doing wrong? Unfortunately I didn't find the necessary article in the Internet. There are a lot of such examples: ($_.Name -eq "name") - and nothing valueable for me.
Upvotes: 1
Views: 2914
Reputation: 9991
I think the issue is how you defined your function.
function enc
{
param ([string]$inp)
return [System.Text.Encoding]::GetEncoding("windows-1251").GetString([System.Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes($inp))
}
$req.Links | Where-Object { (enc $_.innerText) -eq "my string"} | fl
Simple test:
$a = "hello","world"
function enc
{
param ([string]$inp)
$inp
}
$a | Where-Object { (enc $_) -eq "hello"}
Upvotes: 5