Skip to content

Instantly share code, notes, and snippets.

@atao
Created August 23, 2017 14:10
Show Gist options
  • Save atao/4224836573a3ee1b051257bad8e61bcf to your computer and use it in GitHub Desktop.
Save atao/4224836573a3ee1b051257bad8e61bcf to your computer and use it in GitHub Desktop.
Create zip from powershell
function copy-ToZip($fileSaveDir){
$srcdir = $fileSaveDir
$zipFile = "$env:localappdata\tmp\Report.zip"
if(-not (test-path($zipFile)))
{set-content $zipFile ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18));(dir $zipFile).IsReadOnly = $false}
$shellApplication = new-object -com shell.application;$zipPackage = $shellApplication.NameSpace($zipFile)
$files = Get-ChildItem -Path $srcdir
foreach($file in $files){$zipPackage.CopyHere($file.FullName);while($zipPackage.Items().Item($file.name) -eq $null){Start-sleep -seconds 1 }}
}
$fileSaveDir = 'C:\Users\USER\AppData\Local\tmp\blabla'
copy-ToZip($fileSaveDir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment