forked from Aynyuh/EdgeZipServer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make-archive.ps1
53 lines (43 loc) · 1.37 KB
/
make-archive.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using namespace System.IO;
using namespace System.IO.Compression;
[CmdletBinding()]
param(
[string]
$SourceFolder,
[string]
$OutputFileName,
[CompressionLevel]
$CompressionLevel = [CompressionLevel]::Fastest
)
function Force-Resolve-Path {
<#
.SYNOPSIS
Calls Resolve-Path but works for files that don't exist.
.REMARKS
From http://devhawk.net/blog/2010/1/22/fixing-powershells-busted-resolve-path-cmdlet
#>
param (
[string] $Path
)
$Path = Resolve-Path -Path $Path -ErrorAction SilentlyContinue -ErrorVariable _frperror
if (-not($Path)) {
$Path = $_frperror[0].TargetObject
}
return $Path
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
# Construction result absolute paths
$SourcePath = Resolve-Path -Path $SourceFolder
$DestinationArchiveName = Force-Resolve-Path -Path $OutputFileName
# verbose output of result parameters
Write-Verbose -Message "Source folder: `"$SourcePath`""
Write-Verbose -Message "Destination archive: `"$DestinationArchiveName`""
Write-Verbose -Message "Compression: `"$CompressionLevel`""
if (Test-Path -Path $SourcePath -PathType Container)
{
[ZipFile]::CreateFromDirectory($SourcePath, $DestinationArchiveName, $CompressionLevel, $false)
}
else
{
throw "Can't access source path `"$SourcePath`""
}