Reputation: 649
I have log files stored in several sub-directories of a folder D:\TILT_Logs
. I want to combine all of the files into one document, D:\TILT_Logs\Combined.log
.
My current script appears to be skipping some of the files, but I am not sure why.
$combine = GCI 'D:\TILT_Logs' -Recurse -Filter '*.log'
Get-Content $combine.FullName | Set-Content 'D:\TILT_Logs\Combined.log'
When I open Combined.log
it is missing data from some of the log files, but I cannot figure out why they are being skipped.
**EDIT - I also ran echo $combine
to make sure that my GCI was addressing all the files and it is. All files are addressed by the GCI and are echoed, however only a small portion of the files are going into Combined.log
Some of the files that appear to have been skipped are
D:\TILT_Logs\Dec\12_29\Tilt.12892.2017_12_29.log
and
D:\TILT_Logs\March\3_6_Kutchey\Tilt.4740.2018_03_06.log
Does anyone have an idea?
Thanks
Upvotes: 0
Views: 21
Reputation: 857
If you used the Add-Content
commandlet it will append instead of replace
$combine = GCI 'D:\TILT_Logs' -Recurse -Filter '*.log'
Get-Content $combine.FullName | Add-Content 'D:\TILT_Logs\Combined.log'
EDIT Simplifying these commands into one line also will work, credit to Mathias R. Jessen
Get-ChildItem 'D:\TILT_Logs' -Recurse -Filter '*.log' | Get-Content | Add-Content 'D:\TILT_Logs\Combined.log'
Upvotes: 3