I have a DLL assembly that returns a List(of EmailItem). EmailItem is a custom class that includes some properties that lazy load due to the processing time they take to execute. They're basically helpers based on my business requirements.
When I work with these objects in my Windows Service and console applications, these properties sit there quietly waiting to be called.
However if I use PoSh to retrieve a set of these classes, then use Where-Object to filter them, each of these properties is evaluated even though they are not referenced in the Where-Object scriptblock or anywhere else in the script. I've tried writing a custom filter but experience the same behavior. Even projecting the values I care about using Select-Object does the same thing.
My best wild-ass guess is that the objects are being converted to PSObjects and PowerShell is populating the properties.
Any ideas how to avoid this or turn it off for this script? I'm in the process of adding "lightweight" objects that don't include these helpers, but that's an annoying amount of work just to support my favorite Windows scripting language.
Thanks for any tips!
Where-Objectdoes not work as you describe. Is it possible that your properties are actually evaluated when the results are being written to the console? Then all properties can be evaluated indeed.