-
Notifications
You must be signed in to change notification settings - Fork 95
/
Add-Zip.ps1
37 lines (29 loc) · 1.07 KB
/
Add-Zip.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# http://stackoverflow.com/questions/11021879/creating-a-zipped-compressed-folder-in-windows-using-powershell-or-the-command-l
# when using in foreach, must sleep -m 500 after every file
# on conflict, popup will ask to copy and replace
function Add-Zip {
param (
[string]$sourceFile,
[string]$zipFile
)
begin {
function Resolve-FullPath ([string]$Path) {
if ( -not ([System.IO.Path]::IsPathRooted($Path)) ) {
# $Path = Join-Path (Get-Location) $Path
$Path = "$PWD\$Path"
}
[IO.Path]::GetFullPath($Path)
}
}
process {
$sourceFile = Resolve-FullPath $sourceFile
$zipFile = Resolve-FullPath $zipFile
if (-not (Test-Path $zipFile)) {
Set-Content $zipFile ('PK' + [char]5 + [char]6 + ([string][char]0 * 18))
(Get-Item $zipFile).IsReadOnly = $false
}
$shell = New-Object -ComObject shell.application
$zipPackage = $shell.NameSpace($zipFile)
$zipPackage.CopyHere($sourceFile)
}
}