Loop through a list of CSV files in Powershell

This is a simple question so I hope you can help me.
I have a list of 150 CSV files called file1, file2, file3 etc..
I need to run a Powershell script going through every file
Right now im doing this manually by every CSV with this.

Import-Csv .\PD\file1.csv | .\script.ps1

>Solution :

Use Get-ChildItem to discover the files on disk, then use ForEach-Object to process them 1 by 1:

Get-ChildItem path\to\directory -File -Filter *.csv |ForEach-Object {
  Import-Csv $_.FullName | .\script.ps1

The FullName property will contain the rooted path to the file, eg. C:\path\to\PD\file1.csv

Leave a Reply