-
Notifications
You must be signed in to change notification settings - Fork 2
/
Platform-Tools-Installer.ps1
48 lines (41 loc) · 1.51 KB
/
Platform-Tools-Installer.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
36
37
38
39
40
41
42
43
44
45
46
47
48
if ($Host.Version.Major -lt 5) {
Write-Host -Object 'PowerShell 5 or higher is required.' -ForegroundColor 'Red'
Start-Sleep -Seconds 2
Exit
}
$ErrorActionPreference = 'Stop'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Add-Type -AssemblyName 'System.Windows.Forms'
$folderDialog = New-Object -TypeName 'System.Windows.Forms.FolderBrowserDialog'
Write-Verbose -Message 'Downloading Platform Tools...' -Verbose
$Parameters = @{
Uri = 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip'
OutFile = "$env:Temp\platform-tools.zip"
UseBasicParsing = $true
}
Invoke-WebRequest @Parameters
Write-Host
Write-Host -Object 'Please choose a folder to install Platform Tools'
if ($folderDialog.ShowDialog() -eq 'OK') {
Write-Host
Write-Verbose -Message 'Unpacking Platform Tools...' -Verbose
$Parameters = @{
Path = "$env:Temp\platform-tools.zip"
Destination = $folderDialog.SelectedPath
Force = $true
}
Expand-Archive @Parameters
$platformToolsPath = "$($folderDialog.SelectedPath)\platform-tools"
if ($env:Path -notlike "*$platformToolsPath*") {
[Environment]::SetEnvironmentVariable('Path', "$env:Path`;$platformToolsPath", 'User')
}
Remove-Item -Path $Parameters.Path -Force
Write-Host
Write-Host -Object 'Platform Tools has been successfully installed!' -ForegroundColor 'Green'
Start-Sleep -Seconds 2
}
else {
Write-Host
Write-Host -Object 'Folder has not been selected!' -ForegroundColor 'Red'
Start-Sleep -Seconds 2
}