What is different on 2 system.object

Welcome Forums General PowerShell Q&A What is different on 2 system.object

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

 
Senior Moderator
3 weeks, 6 days ago.

  • Author
    Posts
  • #172441

    Participant
    Topics: 3
    Replies: 4
    Points: 18
    Rank: Member

    Hello All,

    I have scipt what is reading csv file and generate there graphs.
    I don't understand what is difference $data and $res.
    Because $data is not working but $res does work.

    	
    $DataFileName = "c:\temp\sample.file"
    
    $data = Import-CSV $DataFileName -Delimiter "`t"  
    
    $data = $data | 	
    Select-Object @{Name="DateTime"; Expression={[datetime]::parseexact($_."DateTime","dd.MM.yyyy HH:mm:ss",$null)}} ,
    	      @{Name="Delay"; Expression={[int]$_."RoundtripTime"}} 
    			  
    $res = foreach ( $i in $Data ) {
        [PSCustomObject]@{
            DateTime = ([datetime]$i."DateTime")
            Delay = ([int]$i."Delay")	
        }
    }		
    ...
    ...
    ...
    # Graph Creation
    # Not Working
    $chart.Series["Delay"].Points.DataBindXY($data.DateTime, $data.Delay)
    
    # Working
    $chart.Series["Delay"].Points.DataBindXY($res.DateTime, $res.Delay)
    
    $data.gettype()
    
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     Object[]                                 System.Array
    
    $res.gettype()
    
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     Object[]                                 System.Array
    
  • #172664

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,439
    Helping Hand
    Rank: Community Hero

    AFAIK, no difference. Both results in same type of object. Select-Object is the neat and clean approach unless there is nothing more to do in a foreach other than object creation.

You must be logged in to reply to this topic.