-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnzip.ps1
More file actions
69 lines (58 loc) · 1.67 KB
/
Unzip.ps1
File metadata and controls
69 lines (58 loc) · 1.67 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<#
.DESCRIPTION
Unzip the given zip file, and copy the contents to the specified destination.
.PARAMETER Source
[Required, String]
Current location of the target zip file. Shall be an absolute path.
.PARAMETER Destination
[Required, String]
Location that zip file's contents will be copied to. Shall be an absolute path.
.PARAMETER DeleteZip
[Optional, Switch]
After unzipping to the destination:
If enabled, then delete the zip file from the source path.
Otherwise, leave it alone.
#>
Param(
[Parameter(Mandatory=$True)]
[string]$Source,
[Parameter(Mandatory=$True)]
[string]$Destination,
[switch]$DeleteZip
)
function ValidateInputs
{
[array]$errorMessageList = @()
if (!(Test-Path $Source)) {
$errorMessageList += $Source
}
if (!(Test-Path $Destination)) {
$errorMessageList += $Destination
}
if ($errorMessageList.Length -gt 0) {
[string]$errorMessage = "Cannot find file(s) " + [string]::Join(" and ", $errorMessageList)
throw [System.IO.FileNotFoundException] $errorMessage
}
}
function Unzip
{
[object]$WShell = New-Object -ComObject Shell.Application
[object]$ZippedFolder = $WShell.NameSpace($Source)
# Copy each item within the zipped folder (source namespace) into the
# destination folder/namespace.
$ZippedFolder.Items() | % {
$WShell.NameSpace($Destination).CopyHere($_)
}
# Clean-up files created by CopyHere.
Push-Location
cd $($Source.Substring(0, $Source.LastIndexOf('\')))
if (Test-Path "0") {
del 0
}
Pop-Location
}
ValidateInputs
Unzip
if ($DeleteZip) {
del $Source
}