Author Posts

August 20, 2018 at 11:11 am

I still cannot understand fully, the fundamental idea within Powershell that says the object TYPE changes as one goes from Command A to Command B in a pipeline, and so on. Best to state my dilemma by way of example, because this has bugged me for days/weeks now:

(1) I have a simple CSV file, 4 properties, nothing out-of-the-ordinary or fancy:

> $Infile = MyFile.csv.

(2) I have the following 4 lines of "code":


$values = Import-Csv $Infile -Delimiter / | Where FullName -NE ""
$values.Count
$values | Get-Member
Get-Member -InputObject $values

(3) Now the key distinction which I do not understand: last 3rd and the 4th lines.  They are to me, the same.  But they're not, according to Powershell.

(4) $values | Get-member  — returns object TYPE PSCustomObject.  Well and good, this what I'm used to most of the time.  The methods and properties displayed are exactly what I was expecting.

(5) Get-Member -InputObject $values — returns System.Object[] – with many many more methods and properties, all of which are Greek to me.  How so?

I am certainly missing some fundamental principle of Powershell processing.  Would be grateful for any hints or advice to get my head straight on this.  Thanking you all out there for your help.

 

 

August 20, 2018 at 11:22 am

You might re-review the help for Get-Member.

Using the InputObject parameter is not the same as piping an object to Get-Member. The differences are as follows:

When you pipe a collection of objects to Get-Member, Get-Member gets the members of the individual objects in the collection, such as the properties of each string in an array of strings.
When you use InputObject to submit a collection of objects, Get-Member gets the members of the collection, such as the properties of the array in an array of strings.