PowerTip: Get Row from CSV File Based On Value

Doctor Scripto

Summary: Use Windows PowerShell to get a row from a CSV file based on a specific value.

Hey, Scripting Guy! Question How can I use Windows PowerShell 4.0 to look up a specific row from a CSV file I imported into a variable?

Hey, Scripting Guy! Answer Use the Where method, and use a match pattern to search on a specific column and value, for example:

$topics = import-csv -Path C:\lit\Shakespeare.txt

$topics.Where({$PSItem.play -eq 'hamlet'}).topic

0 comments

Discussion is closed.

Feedback usabilla icon