Skip to content

Instantly share code, notes, and snippets.

@fatherjack
Last active July 27, 2020 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatherjack/f28b6f3ae8df8d363a3f810d894aadf3 to your computer and use it in GitHub Desktop.
Save fatherjack/f28b6f3ae8df8d363a3f810d894aadf3 to your computer and use it in GitHub Desktop.
When you have a set of files to email and if you zip them all the zip is too large for your email limit. Zip them into a set of zip files
<#
Zips a set of files into a set of zip files with a max size to allow emailing of zip files in size-restricted email environment.
Imagine 20 evenly sized files that need to be zipped and when compressed into a single .zip file, the file is 65MB. With an Exchange
email size limit of 15MB this cannot be sent by email. Using this function you can set a ZipSize limit of 12MB and then the output
will be 5 .zip files with a size around 12MB and one of around 5MB.
No source file will be spanned across zip files so the actual balance of zip file sizes will vary.
#>
$TargetFolder = "C:\temp\APP"
$ZipNames = 1..9 | % { "APP$($_.ToString('00')).zip"}
$ZIPID = 0
$ZipSize = 15mb
$ZipTarget = join-path -Path $TargetFolder $ZipNames[$ZIPID]
foreach($File in gci C:\temp\APP ){
if((Get-ItemProperty -Path $ZipTarget -Name length -ErrorAction SilentlyContinue).Length -lt $ZipSize ){
Write-Output $($File.Name)
compress-Archive -Path $File -destinationpath $ZipTarget -Update
}
else{
Write-Output $($File.Name)
++ $ZIPID
$ZipTarget = join-path -Path $TargetFolder $ZipNames[$ZIPID]
compress-Archive -Path $File -destinationpath $ZipTarget
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment