For the CSV file below, I want to search for each type of Fruit in the file and display the last entry via PowerShell. I've tried the following but I'm getting a blank output.
$fruits = Import-Csv Fruits.csv | select Fruit | sort-object -Property Fruit -Unique
foreach ($fruit in $fruits)
{
Import-CSV Fruits.csv | Select-String -Pattern $fruit
}
Fruits.csv file:
Fruit, Weight
Apple, 3 pounds
Apple, 4 pounds
Apple, 10 pounds
Orange, 3 pounds
Kiwi, 3 pounds
Grape, 2 pounds
Orange, 13 pounds
Grape, 3 pounds
Apple, 6 pounds
Apple, 2 pounds
Expected output:
Apple, 2 pounds
Orange, 3 pounds
Kiwi, 3 pounds
Grape, 2 pounds
Can anyone help in resolving this?