system-utils.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
#
# system_utils.ps1
#
#http://www.adminarsenal.com/admin-arsenal-blog/powershell-zip-up-files-using-net-and-add-type/
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
    )
    Write-Verbose "Compress directory $SourceDirectory to $DestinationFileName"
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    $CompressionLevel    = [System.IO.Compression.CompressionLevel]::$CompressionLevel  
    [System.IO.Compression.ZipFile]::CreateFromDirectory($SourceDirectory, $DestinationFileName, $CompressionLevel, $IncludeParentDir)
}


function UnZip-Directory {
    Param(
      [Parameter(Mandatory=$True)][string]$SourceZipFile,
      [Parameter(Mandatory=$True)][string]$DestinationDirectory
    )

    Add-Type -AssemblyName System.IO.Compression.FileSystem
    
    [System.IO.Compression.ZipFile]::ExtractToDirectory($SourceZipFile, $DestinationDirectory)
}