-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expand-WebArchive.psm1
43 lines (41 loc) · 1.4 KB
/
Expand-WebArchive.psm1
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
function Expand-WebArchive
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
Position=0)]
[string]$Uri,
[Parameter(Mandatory=$false,
Position=1)]
[string]$DestinationPath = "."
)
Begin
{
# Create temporary file with the name of the archive to download
#
# NOTE 1: New-TemporaryFile is force evaluated before Rename-Item due to
# the () around it.
#
# NOTE 2: The URI is split by the '/' characters and the last part is taken
#
# NOTE 3: -PassThru is provided so the modified item is returned for assignment
$TempFile = Rename-Item (New-TemporaryFile) -NewName ($Uri.Split('/')[-1]) -PassThru;
Write-Verbose -Message "Created temporary file $TempFile";
}
Process
{
# Download content into temporary file
Write-Verbose -Message "Dowloading $Uri into temporary archive";
Invoke-WebRequest -Uri $Uri -OutFile $TempFile;
# Expand the archive into the desired destination
Write-Verbose -Message "Expanding temporary archive to $DestinationPath";
Expand-Archive -Path $TempFile.FullName -DestinationPath $DestinationPath;
}
End
{
# Remove the downloaded temporary
Write-Verbose -Message "Removing temporary archive";
Remove-Item $TempFile;
}
}