Following up to this question, it seems like Select-Object sets its input to null as part of its processing. This seems wrong to me. Here's what I'm trying to do:
$sessionInput = new-object -TypeName System.Object
$sessionInput | Add-Member -MemberType NoteProperty -Name Foo -Value $foo
$sessionInput | Add-Member -MemberType NoteProperty -Name Bar -Value $bar
Invoke-Command -Session $session -InputObject $sessionInput {
$foo = $input | Select-Object -ExpandProperty Foo
$bar = $input | Select-Object -ExpandProperty Bar
# Expected: $foo, $bar inside the session = $foo, $bar outside the session
}
What actually happens is that only $foo
has its expected value, and $bar
is always $null
. After a little investigation, it turns out that $input
is set to $null
after the first Select-Object
runs. As an example, inserting $input | Get-Member
in between the two Select-Object
lines throws an error stating that "No object has been specified to the get-member cmdlet."
What is going on here?