Return a row if a column has a partial or perfect match with CSV in Powershell

0

Basically, I want to search for a string and return any full or partial matches in a CSV format.

Let's say I have an object $Shoes that looks like:

"Brand","Style","Color","Price"
"Reebok","Basketball","Red/Black","$50"
"Vans","Slip-On","White/Black","$60"
"Vans","Old Skool","Red/White","$60"
"Nike","Sneakers","Red","$50"
"Adidas","Sneakers","Blue","$55"

To make it more readable, formatting as a table would look like:

Brand       Style       Color       Price
-----       -----       -----       -----
Reebok      Basketball  Red/Black   $50
Vans        Slip-On     White/Black $60
Vans        Old Skool   Red/White   $60
Nike        Sneakers    Red         $50
Adidas      Sneakers    Blue        $55

Typing $Shoes -like '*Red*' returns:

@{Brand=Reebok; Style=Basketball; Color=Red/Black; Price=$50}
@{Brand=Vans; Style=Old Skool; Color=Red/White; Price=$60}
@{Brand=Nike; Style=Sneakers; Color=Red; Price=$50}

But the output I'm looking for is:

Brand       Style       Color       Price
-----       -----       -----       -----
Reebok      Basketball  Red/Black   $50
Vans        Old Skool   Red/White   $60
Nike        Sneakers    Red         $50

What am I doing wrong here?

knorberg

Posted 2020-02-01T22:00:43.510

Reputation: 101

Answers

0

I guess I was formatting -match incorrectly when I tried it, simple solution it turns out...

It's simply $Shoes -match 'Red'

knorberg

Posted 2020-02-01T22:00:43.510

Reputation: 101