This repro’s on 5.1 and 6. The problem is that if I have a DynamicObject that has a dynamic property “Foo”, things like $obj.Foo work, but Select-Object -ExpandProperty Foo do not.
Steps to reproduce
Add-Type @"
using System;
using System.Collections.Generic;
using System.Dynamic;
public class MyDynamicObject : DynamicObject
{
public override IEnumerable<string> GetDynamicMemberNames()
{
return new string[] { "Foo" };
}
public override bool TryGetMember( GetMemberBinder binder, out object result )
{
result = null;
bool succeeded = false;
if( binder.Name == "Foo" )
{
result = 123;
succeeded = true;
}
return succeeded;
}
}
"@
$myObj = [MyDynamicObject]::new()
$myObj.Foo # <-- works
$myObj | %{ $_.Foo } # <-- works
$myObj | Select-Object -ExpandProperty Foo # <-- DOES NOT WORK
Expected behavior
The last three lines should all work (yield 123).
Actual behavior
The Select-Object statement throws. ("Select-Object : Property "Foo" cannot be found.")
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.0-preview.1
PSEdition Core
GitCommitId v6.1.0-preview.1
OS Microsoft Windows 10.0.16299
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
This repro’s on 5.1 and 6. The problem is that if I have a DynamicObject that has a dynamic property “Foo”, things like
$obj.Foowork, butSelect-Object -ExpandProperty Foodo not.Steps to reproduce
Expected behavior
Actual behavior
Environment data