I have a directory containing text files that I need to loop through and remove the first and last line in each file. After that I need to concatenate them and set the output to one file.
My issue is when I loop through the directory it is only manipulating the first file and then stopping. How can I go through each one?
My code:
$path = 'C:\RemoveFirst\*.txt'
$output = 'C:\RemoveFirst\Work.txt'
for ($i = 0; $i -lt $path.Count; $i++) {
Get-Content $path | Select-Object -Skip 1 | Select-Object -SkipLast 1 | Set-Content $output
}