Link to home
Start Free TrialLog in
Avatar of Larry David
Larry David

asked on

Filter .CSV via Powershell

Hello,

Looking to filter a .csv file that contains 15 columns, but I'm only focusing on 2.

My issue that I run into is that I have 2 -eq in my script that export the .csv with nothing. If I remove one of the -eq i get results!

Here is my code:

Import-CSV -path "C:\temp\test1.csv" |

? Column1 -eq "Value1" |

? Column1 -eq "Value2" |


? Column2 -notmatch "Value3" | 

? Column2 -notmatch "Value4" |

? Column2 -notmatch "Value5" |

? Column2 -notmatch "Value6" |

? Column2 -notmatch "Value7" |

? Column2 -notmatch "Value8" |

? Column2 -notmatch "Value9" |


export-csv "C:\temp\test2.csv"

Open in new window


Any ideas on how to bring all the info i need into 1 file?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Larry David
Larry David

ASKER

oBda,

Thank you for the help! Works perfect, the values are all Job Titles in text, but there will be a few the more i work on this that will consist of numbers
Well, are you actually using a regex with -notmatch, or just comparing exact strings?
Comparing exact strings for now. I'm still new to regex, so if you have a article you recommend I can read up on, I'd greatly appreciate it!
EXPERT CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh nice!!!! This will def help my script look a lot cleaner!!

Thank you again!