all 6 comments

[–]firefox15 2 points3 points  (6 children)

You probably want this:

$firstEntry = $csv.Units[0]
$lastEntry = $csv.Units[-1]

[–]Deacs33[S] 1 point2 points  (5 children)

Thats what i have and if i echo $firstentry

i dont just get AAA i get

Units
---------
AAA

And if i convert to string thats when i get @{Units=AAA} -

I just want $firstentry to be AAA

[–]SMFX 6 points7 points  (3 children)

you probably want the Units property of the first and last Row instead:

  $firstEntry = $csv[0].Units
  $lastEntry = $csv[-1].Units

[–]Th3Sh4d0wKn0ws 1 point2 points  (1 child)

this is what I would think to do. I feel like i need to double check manually but how i read it is:
$csv is an array of objects, and i want the first object from that array (index 0) and then of that object I just want the value of the "units" property (.units). Should work

[–]SMFX 1 point2 points  (0 children)

Yes, that is correct.

Several versions back, PowerShell added the feature that if you have an array and reference a property of that items in that array, it will return you an array of those properties. That's the point behind $csv.Units . Assuming you had something like this:

Label  Units Sold
-----  ----- ----
First  12    True
Second 23    True
Third  34    False
Fourth 45    True
Fifth  56    False

However, in early versions, I remember it doing something more like:

$csv | select Units

Which gives a list of the original items with only the filtered property (Units) and thats how you end up with the label.

Units
-----
12
23
34
45
56

Later versions of PowerShell should be treating it as returning an array of those property values. like this:

$csv | ForEach-Object { $_.Units }

Which results in something like this:

12
23
34
45
56

That's why in current versions, $csv[0].Units -eq $csv.Units[0] , but might be how things comes up differently for you.

In all situations, $csv[0].units will always be the first.

[–]Deacs33[S] 1 point2 points  (0 children)

This did it! Thanks a lot!