简体   繁体   English

如何通过 zip 通过 powershell 特别是超过 60 天的文件夹?

[英]How to zip specifically file folders older than 60 days via powershell?

$backup= Compress-Archive -Path 'desired path' -CompressionLevel Fastest -DestinationPath 'desired path'
$backup

I am able to zip up the files in the folder but figuring how to only select files that are 60 days or older in specific is my issue.我能够 zip 更新文件夹中的文件,但我的问题是如何仅计算 select 60 天或更早的文件。 How would I go about something like this?我怎么会 go 这样的事情?

Ive looked at pieces of code like this:我看过这样的代码片段:

$LastWrite = (get-date).AddDays(-30)

$Files = Get-ChildItem -Filter "server.log*" -Recurse -File | Where-Object {$_.LastWriteTime -le $LastWrite}

ForEach ($File in $Files) {
    $File | Compress-Archive -DestinationPath "$($File.fullname).zip"
}

but I am kind of lost但我有点迷路

If I get it right: you would like to add all affected files to one zip.如果我没看错:您想将所有受影响的文件添加到一个 zip。

This should work for you:这应该适合你:

$LastWrite = (get-date).AddDays(-60)

$Files2Compress = Get-ChildItem -Filter "server.log*" -Recurse -File | Where-Object {$_.LastWriteTime -le $LastWrite}

$zipName = (Get-Date).ToString() + '.zip'

Compress-Archive -Path $Files2Compress.FullName -DestinationPath $zipName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM