Search CSV for value. Report if not found.

jat0369
jat0369 used Ask the Experts™
on
I've racked my brain and can't figure this one out.

I've got a script that parses through an existing CSV (two columns) and pulls info from it.
However, I want to process a function if the value entered by the end user is not found (error handling essentially).

What's a simple example of how to do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Active Directory Engineer
Top Expert 2012
Commented:
I'm not sure if this is what you want but you can try it

Clear-Host
$src=Read-Host "Pattern to find"
Import-CSV c:\file.csv | %{

if (($_."column1" -like $src) -or ($_."column2" -like $src))
{ Write-Host $_."column1" +" "+ $_."column2" }
else { Write-Host "Not found" }
}
Write-Host ""
Write-Host "Search finished"

Open in new window


Regards,
Krzysztof

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial