top of page

PowerShell Search and Combine CSV


       To quickly combine multiple CSV files and select only rows with specific text found


        Takes input from folder and selects only CSV files.
        Searches each row and selects only rows of data with select text in the row.
        Exports the data to a CSV file that can be separated out with Text to Columns      


        Run the script and place the folder path at prompt:

        # CSV files under the selected folder
        $Path=Read-host "Enter Folder Path" 
        $Dir = get-childitem $Path -ErrorAction Stop 
        $List = $Dir | where { $_.extension -eq ".csv" } -ErrorAction Stop
        Foreach ($File in $
            $MyFile=Get-Content "$Path\$File" -ErrorAction Stop            
            #Loop through data to get only Item without the No response 
            Foreach ($Line in $MyFile)
                $MyString = $Line.ToString() 
                #Conditional statement to filter out records required 
                If (($Mystring -match "Picked"))
                    #Output data to text file for import to Excel  
                    $Line | out-file $Path\FullList.csv -Append -ErrorAction Stop
        Write-Output $_.Exception 


Ergonomic Keyboards
bottom of page