Skip to content

Instantly share code, notes, and snippets.

@raspi
Created July 14, 2018 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raspi/198875579974471254d5b1a90d2bea2e to your computer and use it in GitHub Desktop.
Save raspi/198875579974471254d5b1a90d2bea2e to your computer and use it in GitHub Desktop.
Download newest nVidia GeForce drivers
# Download latest geforce drivers
# TODO: find a way to get series (ex: GeForce 10 Series) id somehow
Add-Type -AssemblyName System.Web
Import-Module BitsTransfer
$systemLocaleCode = Get-UICulture | select -ExpandProperty LCID
# Get machine's GPUs
$gpus = @{}
foreach($gpu in Get-WmiObject Win32_VideoController){
$tmp = @{
Name = $gpu.VideoProcessor
Version = $gpu.DriverVersion -replace "[^\d]*", "" | % {$_.Substring($_.Length -5).Insert(3, '.')}
Id = -1
}
$gpus += $tmp
}
# List of categories
$urlPre = "http://gfwsl.geforce.com/nvidia_web_services/controller.php?com.nvidia.services.Drivers.getMenuArrays/"
$urlParams = @{
pt = 1 # GeForce
pst = 101 # GeForce 10 Series
d4 = 57 # operating system ID, Windows 10 64-bit
d5 = $systemLocaleCode # language code
driverType = "all"
}
$url = "{0}{1} " -f $urlPre, [System.Web.HttpUtility]::UrlEncode( ($urlParams | ConvertTo-Json -Compress) )
$jsonFile = "$pwd/list.json"
if (!(Test-Path "$jsonFile")) {
Write-Host "Downloading JSON: $url"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, "$jsonFile")
}
$data = Get-Content -Raw -Path $jsonFile | ConvertFrom-Json
# Get GPU ID
foreach($gpu in $gpus){
for ($i = 0; $i -lt $data.Length; $i++) {
foreach ($d in $data[$i]) {
if ($d.menutext -eq $gpu.Name) {
$gpu.Id = $d.id
Break
}
}
}
}
# remove all GPUs with id -1 (not found)
$gpus = $gpus | Where -FilterScript {-Not ($_.Id -eq -1)}
if ($gpus.Length -eq 0) {
Write-Host "GPU IDs not found."
}
# Get list of drivers for GPU x
$driverJsonUrl = [System.UriBuilder]'http://gfwsl.geforce.com/services_toolkit/services/com/nvidia/services/AjaxDriverService.php'
foreach ($gpu in $gpus) {
$dlname = "{0}/{1}.json" -f $pwd, $gpu.Id
$querystr = [System.Web.HttpUtility]::ParseQueryString("")
$querystr["func"] = "DriverManualLookup"
$querystr["pfid"] = $gpu.Id
$querystr["osID"] = $urlParams.d4
$querystr["languageCode"] = $systemLocaleCode
$querystr["beta"] = 0
$querystr["isWHQL"] = 1
$querystr["dltype"] = -1
$querystr["sort1"] = 0
$querystr["numberOfResults"] = 10
$driverJsonUrl.Query = $querystr.ToString()
$url = $driverJsonUrl.ToString()
Write-Host "Downloading JSON: $url"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, "$dlname")
}
# Download driver installer
foreach ($gpu in $gpus) {
$dlname = "{0}/{1}.json" -f $pwd, $gpu.Id
$data = Get-Content -Raw -Path "$dlname" | ConvertFrom-Json
# First one is newest driver
$info = $data.IDS[0].downloadInfo
$found = $false
foreach ($ser in $info.series){
foreach ($prod in $ser.products){
$product = [System.Web.HttpUtility]::UrlDecode($prod.productName)
if ($product -eq $gpu.Name) {
$found = $true
Break
}
}
}
if (!$found) {
Write-Host "GPU product name was not found."
Continue
}
$ver = $info.Version
$url = $info.DownloadURL
$fname = "{0}/{1}" -f $pwd, (Split-Path -Leaf $url)
if ($ver -eq $gpu.Version) {
Write-Host "You are running this version ($ver) already!"
Continue
}
if (Test-Path "$fname") {
Write-Host "$fname exists!"
Continue
}
Write-Host "Downloading driver version $ver"
Write-Host " $fname"
Write-Host " @ $url"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, "$fname")
}
Write-Host ""
Write-Host "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment