copy data from multiple text files with powershell

Hi EE

I am needing to pull three lines from 100s of text files and export to one file .

I have been testing different variations with these and can get it to output from one file but I cant get it to read each source file and export to one file .. can someone assist ?

#This works
Get-Content -Path C:\TESTING\Log.log | Select-Object -Index 4,5,6 | Out-File out_test.txt

#This works
$logfile = Get-Content -Path C:\TESTING\Log.log
$logfile[4,5,6] | Out-File out_test.txt

How to I have it check the directory of the source files and copy those three lines to one file ?  
Thank you all , appreciate the help here always .
LVL 2
MilesLoganAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Does the directory you want to extract the 3 lines from only contain files that you want to extract data from or does it have other files?
0
MilesLoganAuthor Commented:
Only the files I need to extract data from
0
NorieAnalyst Assistant Commented:
Try this.
$folder ="C:\test\TESTING\"
$files = Get-ChildItem $folder

foreach ($file in $files)
{
Get-Content -Path $file.FullName | Select-Object -Index 4,5,6 | Out-File -Append C:\test\out_test.txt
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Challenges in Government Cyber Security

Has cyber security been a challenge in your government organization? Are you looking to improve your government's network security? Learn more about how to improve your government organization's security by viewing our on-demand webinar!

oBdACommented:
This sill give you the file names as well:
Get-ChildItem -Path "C:\test\TESTING\*.log" | ForEach-Object {
	$Name = $_.Name
	Get-Content $_.FullName -TotalCount 6 | Select-Object -Skip 3 -Property @{n='Name'; e={$Name}}, @{n='Line'; e={$_}}
} | Export-Csv -NoTypeInformation -Path out_test.csv

Open in new window

2
MilesLoganAuthor Commented:
That worked perfect ! I was close lol ... I appreciate the quick assistance ..
0
MilesLoganAuthor Commented:
sorry I didnt see your responce oBdA .. that did the trick also ..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.