Need script to import folder list from csv and create a zip file for each folder

Hello,

I am trying to import folder list from csv and create a zip file file for each folder . For example :

C:\Inetpub\vhost\site1.com
C:\Inetpub\vhost\site2.com
C:\Inetpub\vhost\site3.com
C:\Inetpub\vhost\site4.com
C:\Inetpub\vhost\site5.com

and script will create a zip folder for each site in same folder :

C:\Inetpub\vhost\site1.com\site1.com
C:\Inetpub\vhost\site2.com\site2.zip
C:\Inetpub\vhost\site3.com\site2.zip
C:\Inetpub\vhost\site4.com\site4.zip
C:\Inetpub\vhost\site5.com\site5.zip

Then on remote server I want to download all this file and extract each zip for on server.

Could you please help me for the same…

I am new to powershell and its getting difficult for me to do above task…

Thanks
Yatin

Why don’t you start by sharing some of what you’ve already done, and let us know where you’re having difficulty. It’s a lot easier to answer a question than to try and write an entire script for you.

Here is my script :

function Write-ZipUsing7Zip([string]$FilesToZip, [string]$ZipOutputFilePath, [string]$Password, [ValidateSet(‘7z’,‘zip’,‘gzip’,‘bzip2’,‘tar’,‘iso’,‘udf’)][string]$CompressionType = ‘zip’, [switch]$HideWindow)
{
$pathTo32Bit7Zip = “C:\Program Files (x86)\7-Zip\7z.exe”
$pathTo64Bit7Zip = “C:\Program Files\7-Zip\7z.exe”
$THIS_SCRIPTS_DIRECTORY = Split-Path $script:MyInvocation.MyCommand.Path
$pathToStandAloneExe = Join-Path $THIS_SCRIPTS_DIRECTORY “7za.exe”
if (Test-Path $pathTo64Bit7Zip) { $pathTo7ZipExe = $pathTo64Bit7Zip }
elseif (Test-Path $pathTo32Bit7Zip) { $pathTo7ZipExe = $pathTo32Bit7Zip }
elseif (Test-Path $pathToStandAloneExe) { $pathTo7ZipExe = $pathToStandAloneExe }
else { throw “Could not find the 7-zip executable.” }

if (Test-Path $ZipOutputFilePath) { Remove-Item $ZipOutputFilePath -Force }

$windowStyle = "Normal"
if ($HideWindow) { $windowStyle = "Hidden" }



$arguments = "a -t$CompressionType ""$ZipOutputFilePath"" ""$FilesToZip"" -mx9"
if (!([string]::IsNullOrEmpty($Password))) { $arguments += " -p$Password" }

.
$p = Start-Process $pathTo7ZipExe -ArgumentList $arguments -Wait -PassThru -WindowStyle $windowStyle

if (!(($p.HasExited -eq $true) -and ($p.ExitCode -eq 0))) 
{
	throw "There was a problem creating the zip file '$ZipFilePath'."
}

}

But there is some problem with script.
Its create single zip file in yy–mm-dd format (20140304.zip) which include all folders in it.

I want individual zip file for each folder. Then want to use same script to make a zip file of folders which are listed in csv.

Please help.