Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. app1logfolder
  2. |-app1_20130507.log
  3. |-app1_20130508.log
  4. |-app1_20130509.log
  5.  
  6. app2logfolder
  7. |-app2_20130507.log
  8. |-app2_20130508.log
  9. |-app2_20130509.log
  10.  
  11. logs_20130507.zip
  12. |-app1_20130507.log
  13. |-app2_20130507.log
  14.  
  15. logs_20130508.zip
  16. |-app1_20130508.log
  17. |-app2_20130508.log
  18.  
  19. logs_20130509.zip
  20. |-app1_20130509.log
  21. |-app2_20130509.log
  22.  
  23. # load the assembly required
  24. [Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
  25. $sourceFolder = "C:PathToYourLogs"
  26. $destinationFile = "C:PathToYourDestination.zip"
  27. # desired compression level (Optimal, Fastest or NoCompression)
  28. $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
  29. # include the directory $sourceFolder or just it's contents
  30. $includeBaseDirectory = $false
  31.  
  32. [System.IO.Compression.ZipFile]::CreateFromDirectory($sourceFolder, $destinationFile, $compressionLevel , $includeBaseDirectory)
  33.  
  34. $date_string = Get-Date -Format 'yyyyMMdd'
  35.  
  36. $zip_filename = "logs_$date_string.zip"
  37.  
  38. # Create the empty zip file
  39. Set-Content $zip_filename ( [byte[]] @( 80, 75, 5, 6 + (, 0 * 18 ) ) ) -Encoding Byte
  40.  
  41. $zip_file = Get-Item -Path $zip_filename | ForEach-Object {
  42.  
  43. (New-Object -ComObject Shell.Application).NameSpace($_.FullName)
  44. }
  45.  
  46. [array]$log_files = Get-ChildItem -Recurse -Filter "*_$date_string.log"
  47.  
  48. for ($i=1; $i -le $log_files.Count; $i++) {
  49.  
  50. $zip_file.CopyHere($log_files[$i-1].FullName)
  51.  
  52. # Copying is async so we need to check if it is done before continuing.
  53. while ($zip_file.Items().Count -ne $i) { sleep 0.1 }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement