In recursively-count-files-in-subfolders a great working piece of PowerShell code writes to the screen. David comments later that you can redirect to file, but I can't get that to work. I have tried to place it in all kind of different places, but I keep ending up with output writing to screen and an empty file being created.
This is the syntax I would think would work:
dir -recurse | ?{ $_.PSIsContainer } | %{ Write-Host $_.FullName (dir $_.FullName | Measure-Object).Count } | Out-File -FilePath FileCount.txt
It is probably super-simple, but for some reason, the logic behind PowerShell syntax keeps eluding me.