Description
This script gets all CSV’s from an specified folder, and parses them into single Excel sheet.
Source Code
#set root colder to scan for CSV
$folder = 'C:\Temp'
#Get CSV files from folder
$configFiles = Get-ChildItem $folder *.csv
#create excel object
$Excel = New-Object -ComObject excel.application
$workbook = $Excel.workbooks.add()
#initialise line counter
$input = ($configFiles | Out-GridView -PassThru)
$i=1
#Loop through each CSVfile
foreach($file in $configFiles)
{
#Open file stream
$fileInput = [System.IO.File]::OpenText($folder + '\' + $file.Name)
#loop while input lines exist
while($null -ne ($line = $fileInput.ReadLine()))
{
#Initialise sub item counter
$i2=1
#Loop through sub items
$line = $line.Split(",")
foreach($item in $line)
{
#Add subitem to cell
$excel.cells.item($i,$i2) = $item
#increment sub item counter
$i2++
}
#increment line counter
$i++
}
#close stream
$fileInput.Close()
#loop for next file
}
$Excel.visible = $true
taraosborn
(taraosborn)
2
This is great! The only thing I would like to have is for it not to pull the header each time. What do I need to add? Thanks so much!