Use PowerShell to Parse Multiple CSV Files

Adam Bertram

Adam Bertram

Read more posts by this author.

If you’ve got a Cisco ACS server or just have a bunch of CSV files that you’d like to parse this post is for you. I needed to find all unique instances of a MAC address in an EAP Type Name column in a bunch of CSV files. This is the PowerShell script I came up with that worked out great.

This script grabs all CSV files in a directory then finds all instances of where the EAP Type Name column in each CSV equals MS-PEAP. Based on the rows it finds, it then takes out the caller-id column and groups them to remove all of the duplicate instances. It then sort all of these unique caller-ids and export that list to a CSV.

$log_path = '\\cisco-acs\c$\Program Files\CiscoSecure ACS v4.2\Logs\Passed Authentications'
Get-ChildItem $log_path -Recurse -Include *.csv | 
    ForEach-Object { import-csv $_.FullName | Where-Object {$_.'EAP Type Name' -eq 'MS-PEAP'}} | 
    ForEach-Object {$_.'caller-id'} | Group-Object | Select-Object Name | sort Name | 
    Export-Csv -Path 'DevicesUsingPEAP.csv' -NoTypeInformation

Subscribe to Adam the Automator

Get the latest posts delivered right to your inbox

Looks like you're offline!