#Where-Object not working

19 messages · Page 1 of 1 (latest)

rotund onyx
#

Why is my $exceptions variable empty and $abc has not? Forgive the picture please, its on another pc.

red palm
#

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.

fickle star
#

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

rotund onyx
#

Its not iterable. $results just comes from a method that creates custom psobjects

fickle star
#

it'll need to be iterable to pipe it into Where-Object, what is $results.GetType()

rotund onyx
#

I thought methods implicitly return everything as a tuple, is that not iterable? From the screenshot it looks like an array.

red palm
#

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.

fickle star
#

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

rotund onyx
#
function Foo
{
  param(
    [string[]] $foos
  )

   foreach($foo in $foos) {
      [pscustomobject]@{"Image" = "...";"TimeStamp = "...";"Message" = "...";"IsException" = $true}
   } 
}

Its like this

red palm
#

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?

rotund onyx
#

Yes i saw no difference. Ill keep trying

fickle star
#

Just to show you your snippet works by itself

#

check the types of $result, the count, etc