#------------begin script----------------------------- $TimeStamp = Get-Date -UFormat "%Y%m%d_%H%M" # Get date/time stamp of script runtime $myScriptPath = "\\nfxdenfiler1\Shared" # Path of the script $myMergedLogName = New-Item -ItemType file -Path $myScriptPath -name $myLogName -Force # Set the path of the results file $csvFiles = Get-ChildItem -Path $myScriptPath -Filter TMGLOGS_*.csv $content = @() foreach ($csv in $csvFiles) {$content += Import-Csv $myScriptPath\$csv} # I am replacing the comma seperation with a pipe here as the Event Log "message" can/does contain commas (which I do not want to delimit) $content | ConvertTo-Csv -NoType | ForEach-Object {$_.Replace('","','|')} | Out-file $myScriptPath\$myMergedLogName # Remove individual CSV files (aka. "clean-up") $csvFiles | foreach ($_) {remove-item $_.fullname} #------------end script-------------------------------
POWRSHELL: Merge multiple CSV files
Posted by
Jeremy
No comments:
Post a Comment