#Where-Object not working
19 messages · Page 1 of 1 (latest)
you're not making that one easy, eh?
Bit of a blind guess since I've no idea what the origin of your $results variable is.
Try...
$results | Write-Output | Where-Object IsException -eq $true
and see if you get back what you expect.
Check that $results is an actual array/list. You can also do $results | ForEach-Object { "Test '$_' - '$($_.IsException)'" to see if it can be enumerated the the IsException value for each entry
Its not iterable. $results just comes from a method that creates custom psobjects
it'll need to be iterable to pipe it into Where-Object, what is $results.GetType()
I thought methods implicitly return everything as a tuple, is that not iterable? From the screenshot it looks like an array.
you really need to share some code that shows the origin of
did you try ```ps
$results | Write-Output | Where-Object IsException -eq $true
essentially all this does is force enumeration of a potentially unenumerated collection. You see this as a problem with things like ConvertFrom-Json
but it's a theory. Asking us to comment on the screenshot... that's not so hot. It's a bad screenshot with very little useful detail.
things are output and if there are multiple items then it becomes an array. Both are iterable but if you have multiple objects you need to ensure the outermost one is an array with both values rather than an array of an array
but double on what chrisdent is saying here
Regardless you'll have to share more info, like the types, how you are building $results or run some of the suggestions shared here
function Foo
{
param(
[string[]] $foos
)
foreach($foo in $foos) {
[pscustomobject]@{"Image" = "...";"TimeStamp = "...";"Message" = "...";"IsException" = $true}
}
}
Its like this
there is zero chance we'll be able to reproduce the problem with that snippet. It categorically will not exhibit.
but therein lies the problem with "Its like this". Did you try the Write-Output variant to see if it filters correctly?
Yes i saw no difference. Ill keep trying