0

I am trying to generate a file list in a text file using the below PowerShell Command and it generates an empty file every time.

Get-ChildItem "D:\transfer\SprintReporting\" -recurse | where {$_.extension -eq ".csv"} | % {Write-Host $_.FullName | Out-File D:\transfer\SprintReporting\file.txt -Append}

This script generates the output below but doesn't store it in the file. I have tried it with and without Append, inside and outside the loop scope, but nothing has worked so far. Any ideas what I might be missing here?

enter image description here

Nikhil
  • 621
  • 1
  • 13
  • 25
  • 2
    change `write-host` to `write-output`. Have a look at https://stackoverflow.com/questions/19754069/powershell-difference-between-write-host-and-write-output – Itchydon Feb 15 '21 at 15:56
  • I suggest to simplify the last part like this: `% { Add-Content D:\transfer\SprintReporting\file.txt $_.FullName }` – zett42 Feb 15 '21 at 18:48

0 Answers0