I have the following structure of folders,subfolders and files inside each of them C:\Prod\FolderName1 C:\Prod\FolderName1XX C:\Prod\FolderName1YY C:\Prod\FolderName1ZZ
I would like to have all Foldername1 folders with their subfolders and files zipped into a single zip file.
The following works fine with powershell 5.0
$name = Read-Host 'enter the folder NAME'
$namexx = $name + 'xx'
$nameyy = $name + 'yy'
$namezz = $name + 'zz'
$fullpath = join-path -path 'C:\Prod\' -childpath $name
$fullpathxx = join-path -path 'C:\Prod\' -childpath $namexx
$fullpathyy = join-path -path 'C:\Prod\' -childpath $nameyy
$fullpathzz = join-path -path 'C:\Prod\' -childpath $namezz
Compress-Archive -LiteralPath $fullpath,$fullpathxx,$fullpathyy,$fullpathzz -CompressionLevel Optimal -DestinationPath "C:\Dev\$blue $(get-date -f yyyy-MM-dd).zip"
Unfortunately on the server where it has to happen the Powershell is version 2.0 and does not have the Compress-Archive cmdlet.
I tried
Add-Type -Assembly "System.IO.Compression.FileSystem" ;
[System.IO.Compression.ZipFile]::CreateFromDirectory("$fullpath", "c:\dev\$name.zip") ;
but this approach creates multiple zip files for each of the folders. Thanks in advance.