0

I'm running a command to list directories, subdirectories, and a file count. It works fine in powershell but I want it to output to a .txt file. So far all it outputs is a blank file.

dir -recurse |  
  ?{ $_.PSIsContainer } |
    %{ Write-Host $_.FullName (dir $_.FullName |
       Measure-Object).Count }>list.txt
brink
  • 111
  • 7
  • 1
    Remove `Write-Host`. Its only to display stuff to the console not for outputting to a text – Santiago Squarzon May 31 '23 at 01:32
  • 1
    [`Write-Host` is typically the wrong tool to use](http://www.jsnover.com/blog/2013/12/07/write-host-considered-harmful/), unless the intent is to write _to the display only_, bypassing the success output stream and with it the ability to send output to other commands, capture it in a variable, or redirect it to a file. To output a value, use it _by itself_; e.g., `$value` instead of `Write-Host $value` (or use `Write-Output $value`). See the linked duplicate for more information. – mklement0 May 31 '23 at 02:01

0 Answers0