How can I get just counts of the files it removes and add multiple file type's in filter.
Filter:
*.trn and *.bak
Output in LOG file desired after Date Time STuff.
Transaction Logs cleaned --- #
Backup Files Cleaned --- #
"Starting LogCleanup @ $(get-date)" | out-file "F:\SQL-Trn-Bak-Cleanup.txt" # Get files from the directory and all sub-folders # Filter using Where-Object to exclude folders. $logs = get-childitem "\\sql1\Filecopy" -Recurse -Filter "*.bak" | ` ?{ $_.PsIsContainer -eq $False } $year = get-date -f "yyyy" $month = get-date -f "MM" $day = get-date -f "dd" foreach ($file in $logs) { # File is an Object, not a String. $File | out-file "F:\SQL-Trn-Bak-Cleanup.txt" -append if ($file.lastwritetime -lt ($(Get-Date).AddDays(-1))) { remove-item $File.FullName -Force -WhatIf } }
Thanks.