mossrich / PowershellRecipes

21 stars 6 forks source link

Powershell script for monthly archives #3

Closed navinku closed 1 year ago

navinku commented 1 year ago

I am new in powershell and trying to find in the script to modify file creation from monthly to date wise however unable to find. Looking for little help or input.

mossrich commented 1 year ago

I'm assuming you mean ArchiveOldLogs.ps1.

You can change the file name in line 7 to include the date, and it will create a file for each day it runs:

[string] $ZipPath = "$PSScriptRoot\archive-$(get-date -f yyyy-MM-dd).zip", #create one archive per day

However it archives only files that are older than 7 days. If you'd like to archive all files up to yesterday you can change line 6:

$Filter = { $_.LastWriteTime -lt (Get-Date).AddDays(-1)}, #modified yesterday and earlier

Hope this helps!