Log file for powershell script used for deleted files older than 30 days RRS feed

  • Question

  • Hello,

    Below script is for recursive deletion of all files (not folders) older than 30 days exception for some extension to be excluded.

    the script works fine:

    Get-ChildItem -path C:\wsusoffline -exclude *.pdf,*.bat,*.ps1,*.txt -recurse -file -erroraction silentlycontinue | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)}  | ForEach-Object { sdelete $_.FullName } | Out-File C:\logs\log.log

    Now I'm looking for how can I write the output of the result in a CSV log file? (list of deleted files)

    my ideal format for the CSV log would be:

    CurrentDateTime, FileName, FolderName, FilesLastWriteTime

    Thanks for your help

    • Moved by Bill_Stewart Friday, July 7, 2017 6:14 PM This is not "scripts on demand"
    Saturday, May 13, 2017 5:54 AM

All replies

  • Telling what you need is not a scripting question. This forum is for scripting questions and not a free script shop. We don't deliver ready to use solutions. 
    You should urgently consider formatting and indenting your code. It will be much easier for you and for us to understand and to debug in case of need.

    I assume that sdelete does not produce the output you need to create a proper csv log file from. So you would have to create this data "parallel" in the foreach step you kick off sdelete and export that to a csv file.

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Saturday, May 13, 2017 11:39 AM