Script to grab all users and delete file in folder >10days old RRS feed

  • Question

  • I have been scrolling through so many forums and have not found one that helps me.

    I am new to the scripting and there is something I am not understanding.

    I am trying to create a script that is not specific to one user, but to include all users. I need to create a script that will delete all files in the downloads folder that is greater than 10 days. 

    So far this is what I have;

    del c:\Users\Default\Downloads\*

    It deletes everything in the folder and I can not figure out how to have the day set or how to include all users. Please help.

    Thursday, March 27, 2014 9:02 PM

All replies

  • I wrote a script like this to clean up files from a backup folder every 10 days

    $logdir = "f:\backup"
    $now = Get-Date
    $lastwrite = $now.AddDays(-10)

    Get-ChildItem $logdir -Recurse | Where {$_.LastWriteTime -le `
    $lastwrite} | Remove-Item -recurse

    Hope this helps

    • Edited by Brad_Voris Friday, March 28, 2014 4:56 PM
    Friday, March 28, 2014 4:55 PM