-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathZipFolder.ps1
35 lines (30 loc) · 1.52 KB
/
ZipFolder.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
#############################################################################
#
# -SourceFolder = The folder with the files you intend to zip
# -DestinationFile = The zip file that you intend to create
# -Compression = The type of compression you'd like to use:
# Optimal (default option)
# Fastest
# NoCompression
# -IncludeParentDir = Setting this option will include the parent directory
#
#############################################################################
$SourceFolder = "C:\temp\Zip This Folder"
$DestinationFile = "C:\temp\NewZip.zip"
$Compression = "Optimal" # Optimal, Fastest, NoCompression
Zip-Directory -DestinationFileName $DestinationFile `
-SourceDirectory $SourceFolder `
-CompressionLevel $Compression ` #Optional parameter
-IncludeParentDir #Optional parameter
function Zip-Directory {
Param(
[Parameter(Mandatory=$True)][string]$DestinationFileName,
[Parameter(Mandatory=$True)][string]$SourceDirectory,
[Parameter(Mandatory=$False)][string]$CompressionLevel = "Optimal",
[Parameter(Mandatory=$False)][switch]$IncludeParentDir
)
Add-Type -AssemblyName System.IO.Compression.FileSystem
$CompressionLevel = [System.IO.Compression.CompressionLevel]::$CompressionLevel
[System.IO.Compression.ZipFile]::CreateFromDirectory($SourceDirectory, $DestinationFileName, $CompressionLevel, $IncludeParentDir)
}
#############################################################################