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

Viewing 1 reply thread
  • Author
    Posts
    • #172441
      Participant
      Topics: 4
      Replies: 5
      Points: 38
      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: 1163
      Points: 4,071
      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.

Viewing 1 reply thread
  • The topic ‘What is different on 2 system.object’ is closed to new replies.