Created
October 29, 2014 17:07
-
-
Save sweeneyrobb/bdeef74630a38086e3b3 to your computer and use it in GitHub Desktop.
Creates a zip file and adds a file or directory
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 New-Zip ( $zipFile, $file ) { | |
| if ($file -is [string]) { | |
| $file = Get-Item $file | |
| } | |
| set-content $zipFile ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) | |
| $zipFile = Get-Item $zipFile | |
| $zipFile.IsReadOnly = $false | |
| $zip = (New-Object -ComObject shell.application).NameSpace($zipFile.FullName) | |
| if ($file.PSIsContainer) { | |
| $file | get-childitem -exclude $zipFile.Name | foreach-object { | |
| if ($_.Name -ne $zipFile.Name) { | |
| $zip.CopyHere($_.FullName) | |
| # not exactly sure why the wait is needed. prompts dialogs if not here. | |
| Start-Sleep -Milliseconds 200 | |
| } | |
| } | |
| } else { $zip.CopyHere($file.FullName) } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment