Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imjyotiraditya/7a3f474dff0a109d27030dada49be302 to your computer and use it in GitHub Desktop.
Save imjyotiraditya/7a3f474dff0a109d27030dada49be302 to your computer and use it in GitHub Desktop.
# Made by Jyotiraditya Panda
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
$driverPath = "C:\usb-drivers"
Write-Host "Creating directory: $driverPath" -ForegroundColor Green
if (!(Test-Path $driverPath)) {
New-Item -ItemType Directory -Path $driverPath -Force
}
$downloadUrl = "https://dl.google.com/android/repository/usb_driver_r13-windows.zip"
$zipFile = "$env:TEMP\usb_driver_r13-windows.zip"
Write-Host "Downloading Google USB Driver R13..." -ForegroundColor Yellow
try {
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipFile -UseBasicParsing
Write-Host "Download completed successfully!" -ForegroundColor Green
} catch {
Write-Host "Error downloading USB driver: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "`nPress any key to exit..." -ForegroundColor Yellow
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit 1
}
Write-Host "Extracting USB drivers..." -ForegroundColor Yellow
try {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipFile, $driverPath)
Write-Host "Extraction completed!" -ForegroundColor Green
} catch {
Write-Host "Error extracting files: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "`nPress any key to exit..." -ForegroundColor Yellow
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit 1
}
Remove-Item $zipFile -Force
Write-Host "`nLooking for driver installation files..." -ForegroundColor Yellow
$infFiles = Get-ChildItem -Path $driverPath -Filter "*.inf" -Recurse
if ($infFiles.Count -gt 0) {
Write-Host "Found .inf driver files:" -ForegroundColor Green
foreach ($inf in $infFiles) {
Write-Host " $($inf.FullName)" -ForegroundColor Cyan
}
Write-Host "`nInstalling drivers using pnputil..." -ForegroundColor Yellow
foreach ($inf in $infFiles) {
try {
$result = & pnputil /add-driver $inf.FullName /install
Write-Host "Installed: $($inf.Name)" -ForegroundColor Green
} catch {
Write-Host "Failed to install: $($inf.Name) - $($_.Exception.Message)" -ForegroundColor Red
}
}
} else {
Write-Host "No .inf driver files found in the extracted content" -ForegroundColor Red
Write-Host "Please check the extracted files manually at: $driverPath" -ForegroundColor Yellow
}
Write-Host "`nDriver setup process completed!" -ForegroundColor Green
Write-Host "Drivers extracted to: $driverPath" -ForegroundColor Cyan
Write-Host "`nPress any key to exit..." -ForegroundColor Yellow
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment