[Tool][Windows][PowerShell] Android Platform Tools Updater (ADB & Fastboot)

Search This thread

o-l-a-v

Senior Member
Jan 6, 2012
681
537
Oslo
Hi folks,

I've created a PowerShell script which will install or update Android Platform Tools to the latest version. It will also add the install path to Windows Environment Variables, which will make you able to type "adb" or "fastboot" in CMD from anywhere in Windows.

VHDm1K4.png

ADB and Fastboot from anywhere.​

Warning / Disclaimer
  • If this script does any harm or damage, I'm not responsible.
  • This project is very much a hobby project.
  • No guarantees are made.
  • You are responsible for what you do to your system.

License
  • I chose MIT license. You are free to use and reuse this code, but please point to the source (me) if you redestribute it.

Features
  • Installs latest Android Platform Tools (ADB & Fastboot).
  • Updates currently installed Android Platform Tools if newer version is available.
  • Adds Install Path to Windows Environment Variables, System Wide or Current User (controllable by boolean).

Issues of Feature Request
  • Please comment in the thread if you find any issues or have feature requests.
  • I won't guarantee fixes or new features implemented in any timely manner.

Usage
  1. Download script from GitHub.
    • View as RAW.
    • Copy everything over to PowerShell ISE, Notepad++ or similar.
    • Save as "AndroidPlatformToolsUpdater.ps1".
  2. Edit settings to your liking.
  3. Run script as administrator.

Download
 
Last edited:

andacro

Senior Member
Thank you o-1-a-v!

First run I got:

Code:
Installed version is up to date (v0.0.0.0).
 Add-AndroidPlatformToolsToEnvironmentVariables : Cannot validate argument on parameter 'PathDirAndroidPlatformTools'. The "[bool]$(Test-Path -Path 
$_ -ErrorAction 'SilentlyContinue')" validation script for the argument with value "C:\Program Files (x86)\Android Platform Tools" did not return 
a result of True. Determine why the validation script failed, and then try the command again.
At C:\Users\Xxx\Documents\AndroidPlatformToolsUpdater.ps1:335 char:104
+ ... les -PathDirAndroidPlatformTools $PathDirAndroidPlatformTools -System ...
+                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-AndroidPlat...onmentVariables], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Add-AndroidPlatformToolsToEnvironmentVariables
I created the "Android Platform Tools" dir, and then got:

Code:
Installed version is up to date (v0.0.0.0).
 Checking and eventually adding Android Platform Tools to Current User Environment Variables. Success? True.
Running Windows 10.
 

o-l-a-v

Senior Member
Jan 6, 2012
681
537
Oslo
Thank you o-1-a-v!

First run I got:

Code:
Installed version is up to date (v0.0.0.0).
 Add-AndroidPlatformToolsToEnvironmentVariables : Cannot validate argument on parameter 'PathDirAndroidPlatformTools'. The "[bool]$(Test-Path -Path 
$_ -ErrorAction 'SilentlyContinue')" validation script for the argument with value "C:\Program Files (x86)\Android Platform Tools" did not return 
a result of True. Determine why the validation script failed, and then try the command again.
At C:\Users\Xxx\Documents\AndroidPlatformToolsUpdater.ps1:335 char:104
+ ... les -PathDirAndroidPlatformTools $PathDirAndroidPlatformTools -System ...
+                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-AndroidPlat...onmentVariables], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Add-AndroidPlatformToolsToEnvironmentVariables
I created the "Android Platform Tools" dir, and then got:

Code:
Installed version is up to date (v0.0.0.0).
 Checking and eventually adding Android Platform Tools to Current User Environment Variables. Success? True.
Running Windows 10.

Thanks for feedback, I'll look into it :)
 
  • Like
Reactions: andacro

o-l-a-v

Senior Member
Jan 6, 2012
681
537
Oslo
Made a script that can install ADB drivers on Windows. Not thoroughly tested, but seems to work.

C#:
#Requires -RunAsAdministrator
#Requires -Version 5.1
<#
    .SYNOPSIS
        Downloads and installs Google ADB drivers for Windows.

    .DESCRIPTION
        Downloads and installs Google ADB drivers for Windows.

        * Currently there is no logic to check installed version vs. what's available.
        * If already installed, running the script will just install the newest available driver again.

    .NOTES
        # About the script
        Author:   Olav Rønnestad Birkeland | github.com/o-l-a-v
        Created:  220318
        Modified: 220318

        # Resources
        * [Google ADB Drivers](https://developer.android.com/studio/run/win-usb)
        * [PnPUtil return values](https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/pnputil-return-values)

    .EXAMPLE
        & $psISE.CurrentFile.FullPath
#>


# Input parameters
[OutputType($null)]
Param()


# Assets
$Uri = [string] 'https://dl-ssl.google.com/android/repository/latest_usb_driver_windows.zip'
$DownloadPath = [string] '{0}\{1}' -f $env:TEMP, $Uri.Split('/')[-1]
$ExtractDir = [string] $DownloadPath.Replace('.zip','')
$InfFileName = [string] 'android_winusb.inf'


# Download
Write-Output -InputObject '# Download'
if ([System.IO.File]::Exists($DownloadPath)) {
    $null = [System.IO.File]::Delete($DownloadPath)
}
$null = [System.Net.WebClient]::new().DownloadFile(
    $Uri,
    $DownloadPath
)
Write-Output -InputObject ('$? = "{0}", $LASTEXITCODE = "{1}".' -f $?.ToString(), $LASTEXITCODE)


# Extract
Write-Output -InputObject '# Extract'
if ([System.IO.Directory]::Exists($ExtractDir)) {
    $null = [System.IO.Directory]::Delete($ExtractDir,$true)
}
$null = Expand-Archive -Path $DownloadPath -DestinationPath $ExtractDir
Write-Output -InputObject ('$? = "{0}", $LASTEXITCODE = "{1}".' -f $?.ToString(), $LASTEXITCODE)


# Install .INF
Write-Output -InputObject '# Install .INF'
$InfFilePath = [string](Get-ChildItem -Path $ExtractDir -Filter $InfFileName -Recurse -File | Select-Object -ExpandProperty 'FullName')
$null = cmd /c ('pnputil.exe /add-driver "{0}" /install' -f $InfFilePath)
Write-Output -InputObject ('$? = "{0}", $LASTEXITCODE = "{1}".' -f $?.ToString(), $LASTEXITCODE)


# Check results
Write-Output -InputObject '# Checking if driver is found after install'
$InstalledDriver = [array](
    Get-WindowsDriver -Online -All | Where-Object -FilterScript {$_.'ClassName' -eq 'AndroidUsbDeviceClass'}
)
if ($InstalledDriver.'Count' -ge 1) {
    Write-Output -InputObject 'Found the driver.'
    Exit 0
}
else {
    Throw 'Did not find the driver.'
    Exit 1
}

Maybe I'll add the to the main script later. :)
 

Top Liked Posts

  • There are no posts matching your filters.
  • 4
    Hi folks,

    I've created a PowerShell script which will install or update Android Platform Tools to the latest version. It will also add the install path to Windows Environment Variables, which will make you able to type "adb" or "fastboot" in CMD from anywhere in Windows.

    VHDm1K4.png

    ADB and Fastboot from anywhere.​

    Warning / Disclaimer
    • If this script does any harm or damage, I'm not responsible.
    • This project is very much a hobby project.
    • No guarantees are made.
    • You are responsible for what you do to your system.

    License
    • I chose MIT license. You are free to use and reuse this code, but please point to the source (me) if you redestribute it.

    Features
    • Installs latest Android Platform Tools (ADB & Fastboot).
    • Updates currently installed Android Platform Tools if newer version is available.
    • Adds Install Path to Windows Environment Variables, System Wide or Current User (controllable by boolean).

    Issues of Feature Request
    • Please comment in the thread if you find any issues or have feature requests.
    • I won't guarantee fixes or new features implemented in any timely manner.

    Usage
    1. Download script from GitHub.
      • View as RAW.
      • Copy everything over to PowerShell ISE, Notepad++ or similar.
      • Save as "AndroidPlatformToolsUpdater.ps1".
    2. Edit settings to your liking.
    3. Run script as administrator.

    Download
    2
    Updated the tool a bit today. Found more showstopper bugs. But think it's at least usefull now. :)
    1
    Thanks looks promising will try it out this evening
    1
    Thank you o-1-a-v!

    First run I got:

    Code:
    Installed version is up to date (v0.0.0.0).
     Add-AndroidPlatformToolsToEnvironmentVariables : Cannot validate argument on parameter 'PathDirAndroidPlatformTools'. The "[bool]$(Test-Path -Path 
    $_ -ErrorAction 'SilentlyContinue')" validation script for the argument with value "C:\Program Files (x86)\Android Platform Tools" did not return 
    a result of True. Determine why the validation script failed, and then try the command again.
    At C:\Users\Xxx\Documents\AndroidPlatformToolsUpdater.ps1:335 char:104
    + ... les -PathDirAndroidPlatformTools $PathDirAndroidPlatformTools -System ...
    +                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Add-AndroidPlat...onmentVariables], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Add-AndroidPlatformToolsToEnvironmentVariables
    I created the "Android Platform Tools" dir, and then got:

    Code:
    Installed version is up to date (v0.0.0.0).
     Checking and eventually adding Android Platform Tools to Current User Environment Variables. Success? True.
    Running Windows 10.

    Thanks for feedback, I'll look into it :)
    1
    Script updated with better logic to detect available version vs. installed version. :)
    1642941638880.png