Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: WriteOutput help

$
0
0

You’re writing directly to the console. It isn’t intended to be redirected.

Use Write-Output instead. That writes to the pipeline and can be redirected.

Or, if you only want to write to a file, use Out-File.

$searchOption =[IO.SearchOption]::AllDirectories
$fileEntries = [IO.Directory]::GetFiles("\\cd1001-c100\public\isantillan", "*.*", $searchOption);
foreach($fileName in $fileEntries)
{
$fileName | Out-File "D:\Backups\Pdrive cleanup\files_to_delete.txt"

}

I was able to get it to out to file with your suggestion. The only issue is it only outputs 1 line instead of listing all the files in that given directory. :(


Viewing all articles
Browse latest Browse all 13067

Trending Articles