Retro69
Retro69

Reputation: 57

No Output Powershell Script

There is no output to this script when I run it. I think that its something obvious but although it creates the test.txt, no data is put in it on files that it deletes!

Thanks in advance

$limit = (Get-Date).AddDays(-7) 
Get-ChildItem 'C:\temp' -Recurse | 
Where-Object {
 -not $_.PSIsContainer -and $_.CreationTime -lt $limit 
} |  Remove-Item | Out-File -FilePath c:\text.txt

Upvotes: 1

Views: 1605

Answers (1)

Keith Hill
Keith Hill

Reputation: 201662

Remove-Item has no output. You can enable verbose output from Remove-Item and then redirect the Verbose stream to the standard output stream like so:

... | Remove-Item -Verbose 4>&1 > c:\text.txt

Upvotes: 4

Related Questions