Search in csv file

Is it possible to somehow implement a search in csv as follows: if the value “Fitter” is in csv, then copy the entire line with this value into a new csv file.

For example:

# first define your "filter", what are you searching for:
[regex] $Filter = "Enter your search string here"

# Specify CSV file location
$File = "$pwd\sample.csv"

# Get file line by line and grab all lines that match
Get-Content $File | Where-Object { $Filter.IsMatch($_) }

This will get all lines that match your search pattern.

If you want to get first match and ignore the rest then replace 3rd line with this:

Get-Content $File | ForEach-Object {
    if ($Filter.IsMatch($_))
        # Output first match
        Write-Output $_

        # Stop processing

Keep in mind that “Filter” is regex pattern here, if your pattern contains regex special characters then escape them, for example:

[regex] $Filter = [regex]::Escape("Enter your pattern here")

I have implemented as follows:

$ Files = "C:\source file.csv"
Get-Content $ Files | Select-String "search value" | Export-Csv "C:\Target file.csv" -Encoding UTF8 -Delimiter ";"

But, for some reason, a lot of unnecessary columns / values appear: