top of page

PowerShell Search and Combine CSV

A network engineer was tasked with reviewing extensive log files from switches and firewalls, and all had the same format but were all in separate files. They only cared about very specific data in these files (30+) and had to open and review each one on a quarterly basis. I decided to write a PowerShell Script to filter all the data and combine required reading to a single report (CSV).

Typing out PowerShell Commands


       Use PowerShell to quickly combine multiple CSV files & filter for 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 

PowerShell Script Excel CSV Filter
bottom of page