Try this example: This will get all files from a directory and compress 5 files for each .zip. You may need to adapt parts of the code to your requirements ( like the 5 to 100, the 5 was for testing less files. )
Set-Location $PSScriptRoot
#UPDATE THIS VARIABLES ACCORDING YOUR NEEDS
$7zip = ".\packages\7zip\7za.exe"
$filesDir = ".\files"
$numberOfFilesPerZip = 5
#-------
$count = 0
$totalFile = 0
$filesToCompress = Get-ChildItem $filesDir
$zipFileName = "1_To_{0}" -f $numberOfFilesPerZip
foreach($file in $filesToCompress){
$totalFile++
$fileFullPath = $file.FullName
if($count -lt $numberOfFilesPerZip){
$count++
} else {
$zipFileName = "{0}_To_{1}" -f $totalFile, ($totalFile + $numberOfFilesPerZip - 1)
$count = 1
}
Invoke-Expression -Command "$7zip a $zipFileName '$fileFullPath'"
}
The output will be
- 1_To_5.7z
- 6_To_10.7z
- 11_To_15.7z
- ...