Created
August 23, 2017 14:10
-
-
Save atao/4224836573a3ee1b051257bad8e61bcf to your computer and use it in GitHub Desktop.
Create zip from powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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