-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-BuildNvidia.ps1
More file actions
187 lines (141 loc) · 5.84 KB
/
Copy pathInstall-BuildNvidia.ps1
File metadata and controls
187 lines (141 loc) · 5.84 KB
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
#requires -RunAsAdministrator
#requires -Version 5.1
[CmdletBinding()]
param (
[Parameter()]
[string]
$bldPath = "C:\temp",
[Parameter()]
[switch]
$driverOnly
)
function Get-WebFile
{
param (
[string]$URI,
[string]$savePath,
[string]$fileName
)
#Add-Log "Attempting to download: $dlUrl"
# make sure we don't try to use an insecure SSL/TLS protocol when downloading files
$secureProtocols = @()
$insecureProtocols = @( [System.Net.SecurityProtocolType]::SystemDefault,
[System.Net.SecurityProtocolType]::Ssl3,
[System.Net.SecurityProtocolType]::Tls,
[System.Net.SecurityProtocolType]::Tls11)
foreach ($protocol in [System.Enum]::GetValues([System.Net.SecurityProtocolType]))
{
if ($insecureProtocols -notcontains $protocol)
{
$secureProtocols += $protocol
}
}
[System.Net.ServicePointManager]::SecurityProtocol = $secureProtocols
try
{
Invoke-WebRequest -Uri $URI -OutFile "$savePath\$fileName"
}
catch
{
Write-Error "Could not download $URI`: $($Error[0].ToString())"
return $null
}
#Add-Log "Downloaded successfully to: $output"
return "$savePath\$fileName"
}
Write-Host -ForegroundColor Green "Searching for supported Nvidia graphics cards."
# GeForce or Quadro
$gpu = Get-CimInstance win32_VideoController
if ($gpu.Name -match "GeForce")
{
<#
METHOD 2
# quadro
https://www.nvidia.com/Download/processDriver.aspx?psid=73&pfid=865&rpf=1&osid=57&lid=1&lang=en-us&ctk=0&dtid=1&dtcid=0
#GeForce
https://www.nvidia.com/Download/processDriver.aspx?psid=107&pfid=877&rpf=1&osid=57&lid=1&lang=en-us&ctk=0&dtid=1&dtcid=1
#>
Write-Host -ForegroundColor Green "Found: $(($gpu.Name | Where-Object { $_ -match "nvidia" }) -join ',')"
Write-Host -ForegroundColor Green "Attempting to find the newest GeForce Game Ready driver."
$dlUrl = "https://www.nvidia.com/Download/processDriver.aspx?psid=107&pfid=877&rpf=1&osid=57&lid=1&lang=en-us&ctk=0&dtid=1&dtcid=1"
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$cookie = New-Object System.Net.Cookie
$cookie.Name = "drvrSel"
$cookie.Value = 'geforce|geforce rtx 20 series|geforce rtx 2080 ti|windows 10 64-bit|english (us)'
$cookie.Domain = 'www.nvidia.com'
$session.Cookies.Add($cookie)
$test = Invoke-WebRequest -Uri $dlUrl -WebSession $session -UseBasicParsing
}
elseif ($gpu.Name -match "Quadro")
{
Write-Host -ForegroundColor Green "Found: $(($gpu.Name | Where-Object { $_ -match "nvidia" }) -join ',')"
Write-Host -ForegroundColor Green "Attempting to find the newest Quadro driver."
$dlUrl = "https://www.nvidia.com/Download/processDriver.aspx?psid=73&pfid=865&rpf=1&osid=57&lid=1&lang=en-us&ctk=0&dtid=1&dtcid=0"
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$cookie = New-Object System.Net.Cookie
$cookie.Name = "drvrSel"
$cookie.Value = 'quadro|quadro series|quadro p620|optimal driver for enterprise (ode) / quadro studio|windows 10 64-bit|english (us)'
$cookie.Domain = 'www.nvidia.com'
$session.Cookies.Add($cookie)
$test = Invoke-WebRequest -Uri $dlUrl -WebSession $session -UseBasicParsing
}
else
{
Write-Warning "Could not detect a supported Nvidia graphics card."
return $null
}
# grab the exe link
$rootUri = "http://us.download.nvidia.com/"
$gfNextPage = Invoke-WebRequest -Uri "$($test.Content)" -UseBasicParsing
$drvUri = $gfNextPage.Links | Where-Object href -match "^.*windows.*\.exe.*$" | ForEach-Object { $_.href.Split('?')[-1].Split('&')[0].Split('=')[-1].TrimStart("/") }
$URI = "$rootUri$drvUri"
$gfFilename = $drvUri.Split('/')[-1]
Write-Host -ForegroundColor Green "Found a driver. Downloading $gfFilename. This may take a while."
# finally, download the file
$gfInstaller = Get-WebFile -URI $uri -savePath $bldPath -fileName $gfFilename
# make sure there is an installer file
if (-NOT (Test-Path $gfInstaller))
{
Write-Error "Did not find a driver install file."
return $null
}
Write-Host -ForegroundColor Green "Attempting to extract and install the driver."
# make sure 7-zip is installed
$7zPath = "$env:programfiles\7-zip\7z.exe"
if (-NOT (Test-Path $7zPath))
{
winget install 7zip.7zip
# make sure 7-zip is installed
$7zPath = "$env:programfiles\7-zip\7z.exe"
if (-NOT (Test-Path $7zPath))
{
Write-Host -ForegroundColor Green "Please manually install 7-zip before continuing. https://7-zip.org"
Write-Host "Press any key to continue..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
# last chance
if (-NOT (Test-Path $7zPath))
{
Write-Error "Failed to detect 7-zip. Cannot proceed. You can manually install the driver from:`n`n$gfInstaller"
}
}
}
# extract the file
$destPath = "$bldPath\$((Get-Item $gfInstaller).BaseName)"
& "$7zPath" x "$gfInstaller" -o"$destPath"
# run silent install
Push-Location $destPath
Write-Host -ForegroundColor Green "Starting Nvidia driver installation."
Write-Host -ForegroundColor Yellow "It is normal for the screen to flash (briefly go dark) multiple times during installation."
if ($driverOnly)
{
Start-Process setup.exe -ArgumentList "-s Display.Driver -clean -noreboot -noeula" -Wait
}
else
{
Start-Process setup.exe -ArgumentList "-s -clean -noreboot -noeula" -Wait
}
Write-Host -ForegroundColor Green "Nvidia driver installation is complete."
Pop-Location
# clean up the installer files
Remove-Item "$gfInstaller" -Force
Remove-Item "$destPath" -Recurse -Force