Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I modify this powershell script so it creates a log of the date time and names of all files that were deleted or previously deleted?
    primarykey
    data
    text
    <p>I wanted to make a PowerShell script that deleted any type of file in a certain folder when they were 7 days old. The problem I am having is creating a log file with the date, time, and names of all the files that were deleted or were previously deleted when the script ran.</p> <p>I am wondering if there is a way of modifying the answer found on this page: <a href="https://stackoverflow.com/questions/12326171/powershell-script-to-delete-sub-folders-and-files-if-creation-date-is-7-days-bu?lq=1">https://stackoverflow.com/questions/12326171/powershell-script-to-delete-sub-folders-and-files-if-creation-date-is-7-days-bu?lq=1</a></p> <p>I would like it so that instead of sending an email with the report it will create one log file of all the files deleted with the names, time, and dates in the folder that I am storing the script (Please note I'd like it to append the log file each time not overwrite it). I am sorry because I do not know how to code so I have been stuck trying to do this myself for a long time now and I have been asking questions and such but still can't seem to get it to work. So yea if anyone can modify that script it would be very appreciated! Thank you!</p> <p>Here is what I did with the script (if it helps) , but it doesn't work (Again I do not know how to code):</p> <pre><code>$report_items = @() # set folder path $dump_path = "C:FileDeleter\AutoDeleteFilesInThisFolder" # set min age of files $max_days = "-7" # get the current date $curr_date = Get-Date # determine how far back we go based on current date $del_date = $curr_date.AddDays($max_days) # get the sub directories $sub_dirs = Get-ChildItem $dump_path | Where-Object {!$_.PSIsContainer } $sub_dirs | % { if (Get-ChildItem $_.FullName -Recurse | Where-Object { $_.LastWriteTime -gt $del_date } ) { $report_items += New-Object -Type PSObject -Property @{ Time = Get-Date -f "hh:mm:ss" Message = "Skipping " + $_.FullName + " because it contains items newer than " + $del_date } } else { Remove-Item $_.FullName -Recurse $report_items += New-Object -Type PSObject -Property @{ Time = Get-Date -f "hh:mm:ss" Message = "Deleting " + $_.FullName + " because it contains no items newer than " + $del_date } } } $report_items | out-file "C:\FileDeleter\PruningReport.txt" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload