Announcement

Collapse
No announcement yet.

auto remove files

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • auto remove files

    Hi,

    we are using windows server 2012 and we are saving backup files on our NAS Drives. Now gradually, our nas drive is filling up with multiple old backup files. Now we want to implement a mechanism to auto delete the files when it reach to 5 days old. I search on google and found the script below but this script is not working for me.

    script :

    $location = Get-ChildItem \\foo.bar\Drop_Zone
    $date = Get-Date
    foreach ($item in $location) {
    # Check to see if this is the readme folder
    if($item.PsIsContainer -and $item.Name -ne '_ReadMe') {
    $itemAge = ((Get-Date) - $item.CreationTime).Days
    if($itemAge -gt 7) {
    Remove-Item $item.FullName -recurse -force
    }
    }
    else {
    # must be a file
    # you can check age and delete based on that or just delete regardless
    # because they didn't follow the policy
    }
    }

    is there any other script can we made or any changes in this...

    thanks..

  • #2
    You have already posted this script and I moved it to the PowerShell Forum
    Please post further replies there.

    Thread locked
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment

    Working...
    X