forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownload-Git.ps1
More file actions
57 lines (47 loc) · 1.78 KB
/
Download-Git.ps1
File metadata and controls
57 lines (47 loc) · 1.78 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
Function Save-GitSetup {
[CmdletBinding()]
Param(
[Parameter(Position = 0,HelpMessage = "Specify the location to store the downloaded file")]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path $_ })]
[string]$Path = $env:TEMP,
[Parameter(HelpMessage = "Show the downloaded file.")]
[switch]$Passthru
)
if ( (Test-IsPSWindows)) {
Try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#download the latest 64bit version of Git for Windows
$uri = 'https://git-scm.com/download/win'
Write-Verbose "Getting latest version of git from $uri"
#get the web page
$page = Invoke-WebRequest -Uri $uri -UseBasicParsing -DisableKeepAlive -ErrorAction Stop
#get the download link
$dl = ($page.links | Where-Object outerhtml -match 'git-.*-64-bit.exe' | Select-Object -first 1 * ).href
Write-Verbose "Found download link $dl"
#split out the filename
$filename = Split-Path $dl -leaf
#construct a filepath for the download
$out = Join-Path -Path $path -ChildPath $filename
Write-Verbose "Downloading $out from $dl"
#download the file
Try {
Invoke-WebRequest -uri $dl -OutFile $out -UseBasicParsing -DisableKeepAlive -ErrorAction Stop
}
Catch {
Throw $_
}
} #try
Catch {
Throw $_
}
Write-Verbose "Download complete"
if ($Passthru) {
Get-Item -Path $out
}
} #if windows
else {
Write-Warning "This command is intended for x64 Windows platforms."
}
} #end function