February 19th, 2015

PowerTip: Get Row from CSV File Based On Value

Doctor Scripto
Scripter

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

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.