Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imjyotiraditya/78e3ef29b4e548544ff1e07b294f87a7 to your computer and use it in GitHub Desktop.
Save imjyotiraditya/78e3ef29b4e548544ff1e07b294f87a7 to your computer and use it in GitHub Desktop.
# ADB and Fastboot Setup Script for Windows
# Run this script in PowerShell as Administrator
# Set execution policy to allow script execution
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
# Create directory for platform tools
$platformToolsPath = "C:\platform-tools"
Write-Host "Creating directory: $platformToolsPath" -ForegroundColor Green
if (!(Test-Path $platformToolsPath)) {
New-Item -ItemType Directory -Path $platformToolsPath -Force
}
# Download the latest platform tools
$downloadUrl = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip"
$zipPath = "$env:TEMP\platform-tools.zip"
Write-Host "Downloading Android Platform Tools..." -ForegroundColor Yellow
try {
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing
Write-Host "Download completed successfully!" -ForegroundColor Green
} catch {
Write-Host "Error downloading platform tools: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
# Extract the zip file
Write-Host "Extracting platform tools..." -ForegroundColor Yellow
try {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, "C:\")
Write-Host "Extraction completed!" -ForegroundColor Green
} catch {
Write-Host "Error extracting files: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
# Clean up the zip file
Remove-Item $zipPath -Force
# Add to PATH environment variable
Write-Host "Adding to PATH environment variable..." -ForegroundColor Yellow
# Get current PATH
$currentPath = [Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::Machine)
# Check if platform-tools is already in PATH
if ($currentPath -notlike "*$platformToolsPath*") {
$newPath = $currentPath + ";" + $platformToolsPath
[Environment]::SetEnvironmentVariable("PATH", $newPath, [EnvironmentVariableTarget]::Machine)
Write-Host "Added $platformToolsPath to system PATH" -ForegroundColor Green
} else {
Write-Host "Platform tools already in PATH" -ForegroundColor Yellow
}
# Refresh environment variables for current session
$env:PATH = [Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::Machine)
# Verify installation
Write-Host "`nVerifying installation..." -ForegroundColor Yellow
try {
$adbVersion = & "$platformToolsPath\adb.exe" version 2>&1
$fastbootVersion = & "$platformToolsPath\fastboot.exe" --version 2>&1
Write-Host "`nInstallation successful!" -ForegroundColor Green
Write-Host "ADB Version: $($adbVersion[0])" -ForegroundColor Cyan
Write-Host "Fastboot Version: $($fastbootVersion[0])" -ForegroundColor Cyan
Write-Host "`nYou can now use 'adb' and 'fastboot' commands from any command prompt." -ForegroundColor Green
Write-Host "You may need to restart your command prompt or PowerShell to use the commands." -ForegroundColor Yellow
} catch {
Write-Host "Error verifying installation: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Try running the tools directly from: $platformToolsPath" -ForegroundColor Yellow
}
Write-Host "`nSetup complete!" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment