Forum Discussion
MicheleSWFWMD
Mar 20, 2023Copper Contributor
How to get output to file from Remove-Item
Very new to Powershell. I have a script that goes through a folder and removes files not accessed within 14 days. I have been unable to get the output of removed files to write to a file.
Get-Childitem D:\Users -Recurse |
where-object {$_.lastAccessTime -lt (get-date).adddays(-14)} |
foreach{remove-item $_.fullname -recurse -force -verbose -whatif}
I've tried redirection, Output-File, etc. I may just be placing it in the wrong spot.
Thanks
5 Replies
Sort By