I've written a simple C# cmdlet, let's call it Get-Data
, that returns an array of objects.
protected override void ProcessRecord() {
base.ProcessRecord();
DummyClass[] refs = new DummyClass[2];
refs[0] = new DummyClass("A", "big");
refs[1] = new DummyClass("B", "small");
base.WriteObject(refs);
return;
}
This is the definition of DummyClass
:
public class DummyClass {
public string Name { get; set; }
public string Type { get; set; }
public DummyClass(string name, string type) {
this.Name = name;
this.Type = type;
}
}
When I run the cmdlet by itself, I get the expected output - one row that has column headings and an additional row for each element of the array.
PS> Get-Data Name Type ---- ---- A big B small
However, when I pipe the output to Select-Object
, I see column headings, but no data rows.
PS> Get-Data | Select-Object -Property Name,Type Name Type ---- ----
I've even tried specifying the number of rows, with no luck:
PS> Get-Data | Select-Object -Property Name,Type -Last 2
Checking the type of Get-Data
returns a data type of DummyClass[]
, which is what I'd expect.
(Get-Data).GetType().FullName
Does anyone have any thoughts on why there are no data rows when I use Select-Object
? I don't know if it matters, but this cmdlet inherits from System.Management.Automation.PSCmdlet
.
Length : 2 LongLength : 2 Rank : 1 SyncRoot : {A, B} IsReadOnly : False IsFixedSize : True IsSynchronized : False – scantrell Nov 18 '19 at 08:25
, and each of the properties (Count, Length etc.) is on a new line in PS. – scantrell Nov 18 '19 at 08:34