Note that the ZipFile
class is not supported prior to .Net Framework 4.5.
Neither the latest and greatest Framework nor external tools are actually required, though. Something like this should also work:
$folder = 'C:\temp\test'
$zipfile = 'C:\path\to\your.zip'
# create the zip file
$b = 'P', 'K', 5, 6 | % { [char]$_ }
$b += 1..18 | % { [char]0 }
[IO.File]::WriteAllBytes($zipfile, [byte[]]$b)
$app = New-Object -COM 'Shell.Application'
$src = $app.NameSpace($folder)
$dst = $app.NameSpace($zipfile)
# copy items from source folder to zip file
$dst.CopyHere($src.Items())
# wait for copying to complete
do {
Start-Sleep -Milliseconds 200
} until ($src.Items().Count -eq $dst.Items().Count)