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
up vote 4 down vote accepted

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.