Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app1logfolder
- |-app1_20130507.log
- |-app1_20130508.log
- |-app1_20130509.log
- app2logfolder
- |-app2_20130507.log
- |-app2_20130508.log
- |-app2_20130509.log
- logs_20130507.zip
- |-app1_20130507.log
- |-app2_20130507.log
- logs_20130508.zip
- |-app1_20130508.log
- |-app2_20130508.log
- logs_20130509.zip
- |-app1_20130509.log
- |-app2_20130509.log
- # load the assembly required
- [Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
- $sourceFolder = "C:PathToYourLogs"
- $destinationFile = "C:PathToYourDestination.zip"
- # desired compression level (Optimal, Fastest or NoCompression)
- $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
- # include the directory $sourceFolder or just it's contents
- $includeBaseDirectory = $false
- [System.IO.Compression.ZipFile]::CreateFromDirectory($sourceFolder, $destinationFile, $compressionLevel , $includeBaseDirectory)
- $date_string = Get-Date -Format 'yyyyMMdd'
- $zip_filename = "logs_$date_string.zip"
- # Create the empty zip file
- Set-Content $zip_filename ( [byte[]] @( 80, 75, 5, 6 + (, 0 * 18 ) ) ) -Encoding Byte
- $zip_file = Get-Item -Path $zip_filename | ForEach-Object {
- (New-Object -ComObject Shell.Application).NameSpace($_.FullName)
- }
- [array]$log_files = Get-ChildItem -Recurse -Filter "*_$date_string.log"
- for ($i=1; $i -le $log_files.Count; $i++) {
- $zip_file.CopyHere($log_files[$i-1].FullName)
- # Copying is async so we need to check if it is done before continuing.
- while ($zip_file.Items().Count -ne $i) { sleep 0.1 }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement