Organising backups in a monthly folder structure with Powershell


Today I want to share a super handy Powershell snippet for creating monthly archives

$LogArchiveDirectory = "C:\logs\unorganised"

get-childitem | % {

    $file = $_.FullName
    $date = Get-Date ($_.LastWriteTime)
    $month = $date.month
    $year = $date.year

    new-item -type Directory -path "$LogArchiveDirectory\$year\$month" -Force
    move-item $file "$LogArchiveDirectory\$year\$month"
}
Posted on 03 Mar 2019 by Joel Murphy. Last updated: September 09, 2019.


Share your thoughts on: 'Organising backups in a monthly folder structure with Powershell':

👀 Looking for more content?

There's plenty more content to explore: