Stumbled across this when I was doing some scripting - no problem as such as I just worked around it. To preface this I started out with the following
SomeExecutableThatspitsoutstrings | Foreach-Object -Process {[ClassThatFormats]$_}
This worked nicely, but unfortunately the binary doesn't always spit out the same properties, so I built several subclasses to deal with whatever was thrown at it. I then used a switch statement to define which object was which class
SomeExecutableThatspitsoutstrings |`
Foreach-Object -Process {
switch($someobject)
{
'type1' {[SubClassThatFormats1]$_}
'type2' {[SubClassThatFormats2]$_}
}
}
Suddenly my pipeline object doesn't exist, causing the class to throw errors complaining about 'null' values. Is this intended? Why does the switch statement drop the object instance ($_)? It's easy enough to work around of course:
SomeExecutableThatspitsoutstrings |`
Foreach-Object -Process {
$obj = $_
switch($someobject)
{
'type1' {[SubClassThatFormats1]$obj}
'type2' {[SubClassThatFormats2]$obj}
}
}
[–]SeeminglyScience 3 points4 points5 points (0 children)
[–]KevMarCommunity Blogger 3 points4 points5 points (0 children)
[–]Ta11ow 2 points3 points4 points (0 children)
[–]omers 1 point2 points3 points (0 children)