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 06, 2019.


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