-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDownload_NVidia_Driver.ps1
231 lines (204 loc) · 7.57 KB
/
Download_NVidia_Driver.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<#
.SYNOPSIS
Check for the latest NVIdia driver version, and if it's lower than the current one download
.PARAMETER Clean
Delete the old driver, reset settings and install the newest one
.EXAMPLE
UpdateNVidiaDriver
.NOTES
Supports Windows 10 x64 & Windows 11 only
.NOTES
Installer 2.0 Command Line Guide
.NOTES
https://docs.nvidia.com/sdk-manager/sdkm-command-line-install/index.html
#>
function UpdateNVidiaDriver
{
Clear-Host
# Checking Windows version
if ([System.Version][Environment]::OSVersion.Version.ToString() -lt [System.Version]"10.0")
{
Write-Verbose -Message "Your Windows is unsupported. Upgrade to Windows 10 or higher" -Verbose
exit
pause
}
# Checking Windows bitness
if (-not [Environment]::Is64BitOperatingSystem)
{
Write-Verbose -Message "Your Windows architecture is x86. x64 is required" -Verbose
exit
pause
}
if (Test-Path -Path "$env:SystemRoot\System32\DriverStore\FileRepository\nv_*\nvidia-smi.exe")
{
# The NVIDIA System Management Interface (nvidia-smi) is a command line utility, based on top of the NVIDIA Management Library (NVML)
$CurrentDriverVersion = nvidia-smi.exe --format=csv,noheader --query-gpu=driver_version
}
else
{
[System.Version]$Driver = (Get-CimInstance -ClassName Win32_VideoController | Where-Object -FilterScript {$_.Name -match "NVIDIA"}).DriverVersion
$CurrentDriverVersion = ("{0}{1}" -f $Driver.Build, $Driver.Revision).Substring(1).Insert(3,'.')
}
Write-Verbose -Message "Current version: $CurrentDriverVersion" -Verbose
Write-Information -MessageData "" -InformationAction Continue
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if ($Host.Version.Major -eq 5)
{
# Progress bar can significantly impact cmdlet performance
# https://github.com/PowerShell/PowerShell/issues/2138
$Script:ProgressPreference = "SilentlyContinue"
}
# Checking latest driver version from Nvidia website
$Parameters = @{
Uri = "https://www.nvidia.com/Download/API/lookupValueSearch.aspx?TypeID=3"
UseBasicParsing = $true
}
[xml]$Content = (Invoke-WebRequest @Parameters).Content
$CardModelName = (Get-CimInstance -ClassName CIM_VideoController | Where-Object -FilterScript {($_.AdapterDACType -notmatch "Internal") -and ($_.Status -eq "OK")}).Caption.Split(" ")
if (-not $CardModelName)
{
Write-Verbose -Message "There's no active videocard in system" -Verbose
exit
pause
}
# Remove the first word in full model name. E.g. "NVIDIA"
$CardModelName = [string]$CardModelName[1..($CardModelName.Count)]
$ParentID = ($Content.LookupValueSearch.LookupValues.LookupValue | Where-Object -FilterScript {$_.Name -contains $CardModelName}).ParentID | Select-Object -First 1
$Value = ($Content.LookupValueSearch.LookupValues.LookupValue | Where-Object -FilterScript {$_.Name -contains $CardModelName}).Value | Select-Object -First 1
# https://github.com/fyr77/EnvyUpdate/wiki/Nvidia-API
# osID=57 — Windows x64/Windows 11
# languageCode=1033 — English language
# dch=1 — DCH drivers
# https://nvidia.custhelp.com/app/answers/detail/a_id/4777/~/nvidia-dch%2Fstandard-display-drivers-for-windows-10-faq
# upCRD=0 — Game Ready Driver
$Parameters = @{
Uri = "https://gfwsl.geforce.com/services_toolkit/services/com/nvidia/services/AjaxDriverService.php?func=DriverManualLookup&psid=$ParentID&pfid=$Value&osID=57&languageCode=1033&beta=null&isWHQL=1&dltype=-1&dch=1&upCRD=0"
UseBasicParsing = $true
}
$Data = Invoke-RestMethod @Parameters
if ($Data.IDS.downloadInfo.Version)
{
$LatestVersion = $Data.IDS.downloadInfo.Version
Write-Verbose -Message "Latest version: $LatestVersion" -Verbose
Write-Information -MessageData "" -InformationAction Continue
}
else
{
Write-Warning -Message "Something went wrong"
exit
}
# Comparing installed driver version to latest driver version from Nvidia
if (-not $Clean -and ([System.Version]$LatestVersion -eq [System.Version]$CurrentDriverVersion))
{
Write-Verbose -Message "The current installed NVidia driver is the same as the latest one" -Verbose
exit
pause
}
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
if (-not (Test-Path -Path "$DownloadsFolder\$LatestVersion-desktop-win10-win11-64bit-international-dch-whql.exe"))
{
# Downloading installer
try
{
$Parameters = @{
Uri = $Data.IDS.downloadInfo.DownloadURL
OutFile = "$DownloadsFolder\$LatestVersion-desktop-win10-win11-64bit-international-dch-whql.exe"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message "Connection cannot be established"
exit
pause
}
}
Write-Warning -Message "Downloading..."
Write-Warning -Message $Data.IDS.downloadInfo.DownloadURL
# Get the latest 7-Zip download URL
try
{
$Parameters = @{
Uri = "https://sourceforge.net/projects/sevenzip/best_release.json"
UseBasicParsing = $true
Verbose = $true
}
$bestRelease = (Invoke-RestMethod @Parameters).platform_releases.windows.filename.replace("exe", "msi")
}
catch [System.Net.WebException]
{
Write-Warning -Message "Connection cannot be established"
exit
pause
}
# Download the latest 7-Zip x64
try
{
$Parameters = @{
Uri = "https://unlimited.dl.sourceforge.net/project/sevenzip$($bestRelease)?viasf=1"
OutFile = "$DownloadsFolder\7Zip.msi"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
}
catch [System.Net.WebException]
{
Write-Warning -Message "Connection cannot be established"
exit
pause
}
# Expand 7-Zip
$Arguments = @(
"/a `"$DownloadsFolder\7Zip.msi`""
"TARGETDIR=`"$DownloadsFolder\7zip`""
"/qb"
)
Start-Process "msiexec" -ArgumentList $Arguments -Wait
# Delete the installer once it completes
Remove-Item -Path "$DownloadsFolder\7Zip.msi" -Force
# Extracting installer
# Based on 7-zip.chm
$Arguments = @(
# Extracts files from an archive with their full paths in the current directory, or in an output directory if specified
"x",
# standard output messages. disable stream
"-bso0",
# progress information. redirect to stdout stream
"-bsp1",
# error messages. redirect to stdout stream
"-bse1",
# Overwrite All existing files without prompt
"-aoa",
# What to extract
"$DownloadsFolder\$LatestVersion-desktop-win10-win11-64bit-international-dch-whql.exe",
# Extract these files and folders
"Display.Driver HDAudio NVI2 NVApp NVApp.MessageBus NVCpl PhysX EULA.txt ListDevices.txt setup.cfg setup.exe",
# Specifies a destination directory where files are to be extracted
"-o`"$DownloadsFolder\NVidia`""
)
$Parameters = @{
FilePath = "$DownloadsFolder\7zip\Files\7-Zip\7z.exe"
ArgumentList = $Arguments
NoNewWindow = $true
Wait = $true
}
Start-Process @Parameters
<# Remove unnecessary dependencies from setup.cfg
[xml]$setup = Get-Content -Path "$DownloadsFolder\NVidia\setup.cfg" -Encoding UTF8 -Force
($setup.setup.manifest.file | Where-Object -FilterScript {@("`${{EulaHtmlFile}}", "`${{FunctionalConsentFile}}", "`${{PrivacyPolicyFile}}") -contains $_.name }) | ForEach-Object {
$_.ParentNode.RemoveChild($_)
}
$setup.Save("$DownloadsFolder\NVidia\setup.cfg")
#>
$Parameters = @{
Path = "$DownloadsFolder\7zip", "$DownloadsFolder\$LatestVersion-desktop-win10-win11-64bit-international-dch-whql.exe"
Recurse = $true
Force = $true
}
Remove-Item @Parameters
Invoke-Item -Path "$DownloadsFolder\NVidia"
}
UpdateNVidiaDriver