Working on csv data

Tagged: , ,

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Stephan Dasia Stephan Dasia 1 year, 7 months ago.

  • Author
    Posts
  • #32482
    Profile photo of Stephan Dasia
    Stephan Dasia
    Participant

    Hi Guys,

    I'm trying to create graphs with powershell, but i hit a snap with the input data.

    I have a table in the form of:

    Name,Date,Aggregate,TotalSize,AvailableSize,UsedSize

    to make a graph i need the input to look as this:

    Name,Date,Aggregate(Totalsize),TotalSize,AvailableSize,UsedSize

    the code i am trying to adapt is this

    (import-csv $LogDir\graph.csv) | Select @{Name="Name";Expression={$_.name}}, @{Name="Date";Expression={$_.date}},@{Name="Aggregate";Expression={{$_.aggregate}{$_.totalsize}}},@{Name="TotalSize";Expression={$_.totalsize}},@{Name="AvailableSize";Expression={$_.Availablesize}},@{Name="UsedSize";Expression={$_.usedsize}}|write-host

    I know this is not working because my aggregates column is empty

    @{Name="Aggregate";Expression={{$_.aggregate}{$_.totalsize}}}

    if i remove the {$_.Totalsize} i will get the aggregate name but that's not what i want
    what do i need to do to get the output as:

    aggregate(totalsize)

    I hope one of you guru's know the answer. if there would be another solution please feel free to add it..

  • #32483
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Something like this?

    $InputData = import-csv $LogDir\graph.csv
    $AggregateTotal = $InputData.aggregate | Measure-Object -Sum | Select-Object -ExpandProperty Sum
    $InputData | Select-Object Name, Date, @{Name="Aggregate(TotalSize)";Expression={$AggregateTotal}}, Totalsize, Availablesize, Usedsize
    
  • #32489
    Profile photo of Stephan Dasia
    Stephan Dasia
    Participant

    Almost, but i've found a solution

    (Import-Csv $LogDir\graph.csv) | Select @{Name="Name";Expression={$_.name}}, @{Name="Date";Expression={$_.date}}, @{Name="Aggregate";Expression={"$($_.aggregate)($($_.totalsize)TB)"}}, @{Name="TotalSize";Expression={$_.totalsize}},@{Name="AvailableSize";Expression={$_.Availablesize}},@{Name="UsedSize";Expression={$_.usedsize}} |export-csv $LogDir\graph2.csv

    This is what i did:
    @{Name="Aggregate";Expression={"$($_.aggregate)($($_.totalsize)TB)"}}

You must be logged in to reply to this topic.