I need to get all the files including the files present in the subfolders that belong to a particular type.
I am doing something like this, using Get-ChildItem:
Get-ChildItem -Recurse *.txt | Format-Table FullName
That is what I used. I feel it is more understandable as it doesn't contain any loop syntax.
Why has nobody used the foreach loop yet? A pro here is that you can easily name your variable:
# Note that I'm pretty explicit here. This would work as well as the line after:
# Get-ChildItem -Recurse C:\windows\System32\*.txt
$fileList = Get-ChildItem -Recurse -Path C:\windows\System32 -Include *.txt
foreach ($textfile in $fileList) {
# This includes the filename ;)
$filePath = $textfile.fullname
# You can replace the next line with whatever you want to.
Write-Output $filePath
}