We have several servers that write log files to C:\\Logs on a daily basis. Every month, a script is supposed to run to identify files older than 30 days, archive them, and delet
Do you have to use 7zip?
I have done the same task using dotnetzip and was able to save the folder structure.
Here is my code, you can use this and add your date logic to it:
[System.Reflection.Assembly]::LoadFrom("c:\\\User\\bin\\Ionic.Zip.dll");
$zipfile = new-object Ionic.Zip.ZipFile("C:\user\temp\logs\TestZIP.zip");
$directory = "C:\user\temp\logs\"
$children = get-childitem -path $directory
foreach ($o in $children)
{
if($o.Name.EndsWith(".log")){
$e = $zipfile.AddFile($o.FullName)
}
}
$zipfile.Save()
$zipfile.Dispose()