Collections/arrays versus Items/rows -- please help!

Welcome Forums General PowerShell Q&A Collections/arrays versus Items/rows -- please help!

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 months, 3 weeks ago.

  • Author
    Posts
  • #109007

    Participant
    Points: 180
    Rank: Participant

    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.

     

     

  • #109010

    Participant
    Points: 261
    Helping Hand
    Rank: Contributor

    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.

The topic ‘Collections/arrays versus Items/rows -- please help!’ is closed to new replies.