Archive/Save-OSDDriverNvidiaPack.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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
<#
.SYNOPSIS Downloads and creates Nvidia Video Driver Packs .DESCRIPTION Downloads and creates Nvidia Video Driver Packs Requires 7-Zip for EXE extraction Requires BITS for downloading the Downloads Requires Internet access .LINK https://osddrivers.osdeploy.com/module/functions/save-osddrivernvidiapack #> function Save-OSDDriverNvidiaPack { [CmdletBinding(DefaultParameterSetName = 'Default')] Param ( #Fully automatic Pack creation [Parameter(ParameterSetName = 'QuickPack', Mandatory = $true)] [ValidateSet('NvidiaPack 10.0 x64','NvidiaPack 10.0 x86','NvidiaPack 6.1 x64','NvidiaPack 6.1 x86')] [string]$QuickPack, #Appends the value to the Driver Pack Name [Parameter(ParameterSetName = 'Default')] [string]$AppendName = 'None', #Driver Pack supported Operating System Architecture [Parameter(ParameterSetName = 'Default')] [ValidateSet ('x64','x86')] [string]$OsArch, #Driver Pack supported Operating System Version [Parameter(ParameterSetName = 'Default')] [ValidateSet ('10.0','6.1')] [string]$OsVersion, #Creates a CAB file from the downloaded Intel Driver [Parameter(ParameterSetName = 'Default')] [switch]$Pack, #Skips GridView for Automation [Parameter(ParameterSetName = 'Default')] [switch]$SkipGridView ) Begin { #=================================================================================================== # Get-OSDDrivers #=================================================================================================== Get-OSDDrivers -CreatePaths -HideDetails #=================================================================================================== # ParameterSetName #=================================================================================================== if ($PSCmdlet.ParameterSetName -eq 'QuickPack') { $CustomName = $QuickPack $Pack = $true $SkipGridView = $true if ($QuickPack -eq 'NvidiaPack 10.0 x64') { $OsArch = 'x64' $OsVersion = '10.0' } if ($QuickPack -eq 'NvidiaPack 10.0 x86') { $OsArch = 'x86' $OsVersion = '10.0' } if ($QuickPack -eq 'NvidiaPack 6.1 x64') { $OsArch = 'x64' $OsVersion = '6.1' } if ($QuickPack -eq 'NvidiaPack 6.1 x86') { $OsArch = 'x86' $OsVersion = '6.1' } } else { if ($AppendName -eq 'None') { $CustomName = "NvidiaPack" } else { $CustomName = "NvidiaPack $AppendName" } } #=================================================================================================== # Require 7-Zip #=================================================================================================== if ($Pack -eq $true) { if (! (Test-Path "$env:ProgramFiles\7-Zip\7z.exe")) { Write-Warning "OSDDrivers: Save-OSDDriverAMDPack requires 7-Zip at $env:ProgramFiles\7-Zip\7z.exe" Write-Warning "OSDDrivers: This is to extract AmdPack and Nvidia Pack Downloads" Write-Warning "OSDDrivers: Pack creation will be disabled" $Pack = $false } } #=================================================================================================== # Get-OSDGather -Property IsAdmin #=================================================================================================== if ($Pack -eq $true) { if ((Get-OSDGather -Property IsAdmin) -eq $false) { Write-Warning 'OSDDrivers: This function needs to be run as Administrator' Write-Warning 'OSDDrivers: This is to generate PNP information' Write-Warning "OSDDrivers: Pack creation will be disabled" $Pack = $false } } #=================================================================================================== # Display Paths #=================================================================================================== Write-Verbose "Home: $GetOSDDriversHome" -Verbose Write-Verbose "Download: $SetOSDDriversPathDownload" -Verbose Write-Verbose "Expand: $SetOSDDriversPathExpand" -Verbose Write-Verbose "Packages: $SetOSDDriversPathPackages" -Verbose #=================================================================================================== # Publish Paths #=================================================================================================== Publish-OSDDriverScripts -PublishPath $SetOSDDriversPathPackages $PackagePath = Get-PathOSDD -Path (Join-Path $SetOSDDriversPathPackages "$CustomName") Write-Verbose "Package Path: $PackagePath" -Verbose Publish-OSDDriverScripts -PublishPath $PackagePath #=================================================================================================== } Process { Write-Verbose '========================================================================================' -Verbose Write-Verbose $MyInvocation.MyCommand.Name -Verbose #=================================================================================================== # Get-OSDDriver #=================================================================================================== $OSDDrivers = @() if ($InputObject) { $SkipGridView = $true $OSDDrivers = $InputObject } else { $OSDDrivers = Get-OSDDriver NvidiaDisplay } #=================================================================================================== # Set-OSDDriver #=================================================================================================== foreach ($item in $OSDDrivers) { $DriverName = $item.DriverName $OSDCabFile = "$($DriverName).cab" $DownloadFile = $item.DownloadFile $OSDGroup = $item.OSDGroup $OSDType = $item.OSDType $DownloadedDriverGroup = (Join-Path $global:SetOSDDriversPathDownload $OSDGroup) $DownloadedDriverPath = (Join-Path $SetOSDDriversPathDownload (Join-Path $OSDGroup $DownloadFile)) if (Test-Path "$DownloadedDriverPath") {$item.OSDStatus = 'Downloaded'} $ExpandedDriverPath = (Join-Path $SetOSDDriversPathExpand (Join-Path $OSDGroup $DriverName)) if (Test-Path "$ExpandedDriverPath") {$item.OSDStatus = 'Expanded'} $PackagedDriverPath = (Join-Path $PackagePath (Join-Path $OSDGroup $OSDCabFile)) if (Test-Path "$PackagedDriverPath") {$item.OSDStatus = 'Packaged'} } #=================================================================================================== # Filters #=================================================================================================== if ($OsArch) {$OSDDrivers = $OSDDrivers | Where-Object {$_.OsArch -match "$OsArch"}} if ($OsVersion) {$OSDDrivers = $OSDDrivers | Where-Object {$_.OsVersion -match "$OsVersion"}} #=================================================================================================== # GridView #=================================================================================================== $OSDDrivers = $OSDDrivers | Sort-Object LastUpdate -Descending if ($SkipGridView.IsPresent) { Write-Warning "OSDDrivers: Skipping Out-GridView Selection" } else { $OSDDrivers = $OSDDrivers | Out-GridView -PassThru -Title "Select Drivers to Download and press OK" } #=================================================================================================== # Download #=================================================================================================== Write-Verbose "===================================================================================================" foreach ($OSDDriver in $OSDDrivers) { $OSDType = $OSDDriver.OSDType Write-Verbose "OSDType: $OSDType" $DriverInfo = $OSDDriver.DriverInfo Write-Verbose "DriverInfo: $DriverInfo" $DriverUrl = $OSDDriver.DriverUrl Write-Verbose "DriverUrl: $DriverUrl" $DriverName = $OSDDriver.DriverName Write-Verbose "DriverName: $DriverName" $DriverGrouping = $OSDDriver.DriverGrouping Write-Verbose "DriverGrouping: $DriverGrouping" $DownloadFile = $OSDDriver.DownloadFile Write-Verbose "DownloadFile: $DownloadFile" $OSDGroup = $OSDDriver.OSDGroup Write-Verbose "OSDGroup: $OSDGroup" $OSDCabFile = "$($DriverName).cab" Write-Verbose "OSDCabFile: $OSDCabFile" $DownloadedDriverPath = (Join-Path $SetOSDDriversPathDownload (Join-Path $OSDGroup $DownloadFile)) Write-Verbose "DownloadedDriverPath: $DownloadedDriverPath" $ExpandedDriverPath = (Join-Path $SetOSDDriversPathExpand (Join-Path $OSDGroup $DriverName)) Write-Verbose "ExpandedDriverPath: $ExpandedDriverPath" $PackagedDriverPath = (Join-Path $PackagePath (Join-Path $DriverGrouping $OSDCabFile)) Write-Verbose "PackagedDriverPath: $PackagedDriverPath" Write-Host "$DriverName" -ForegroundColor Green #=================================================================================================== # Driver Download #=================================================================================================== Write-Host "Driver Download: $DownloadedDriverPath " -ForegroundColor Gray -NoNewline $DownloadedDriverGroup = Get-PathOSDD -Path (Join-Path $SetOSDDriversPathDownload $OSDGroup) if (Test-Path "$DownloadedDriverPath") { Write-Host 'Complete!' -ForegroundColor Cyan } else { Write-Host "Downloading ..." -ForegroundColor Cyan Write-Host "$DriverUrl" -ForegroundColor Gray if ($OSDGroup -eq 'AmdPack') { #Thanks @manelrodero $AmdAsk = Invoke-WebRequest -Uri "$DriverInfo" -Method Get $Headers = @{ Referer = "$DriverInfo" ; Cookie = $AmdAsk.BaseResponse.Cookies } Invoke-WebRequest -Uri "$DriverUrl" -Method Get -Headers $Headers -OutFile "$DownloadedDriverPath" } else { Start-BitsTransfer -Source $DriverUrl -Destination "$DownloadedDriverPath" -ErrorAction Stop } } #=================================================================================================== # AmdPack Manual Download #=================================================================================================== if (-not (Test-Path "$DownloadedDriverPath")) { if ($OSDGroup -eq 'AmdPack') { Write-Host "" Write-Warning "AMD has blocked direct Driver downloads so use this workaround" Write-Host "1) Open the following URL: " -NoNewline -ForegroundColor Cyan Write-Host "$DriverInfo" Write-Host "2) Find the Driver link to " -NoNewline -ForegroundColor Cyan Write-Host "$DownloadFile" Write-Host "3) Save the download as " -NoNewline -ForegroundColor Cyan Write-Host "$DownloadedDriverPath" Write-Host "" Pause } } #=================================================================================================== # Validate Driver Download #=================================================================================================== if (-not (Test-Path "$DownloadedDriverPath")) { Write-Warning "Driver Download: Could not download Driver to $DownloadedDriverPath ... Exiting" Break } #=================================================================================================== # Verify 7zip #=================================================================================================== if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) { Write-Warning "Could not find $env:ProgramFiles\7-Zip\7z.exe" Write-Warning "7-zip is required to expand this Downloaded Driver" Write-Warning "You can download it from https://www.7-zip.org/" Continue } #=================================================================================================== # Driver Expand #=================================================================================================== Write-Host "Driver Expand: $ExpandedDriverPath " -ForegroundColor Gray -NoNewline if (Test-Path "$ExpandedDriverPath") { Write-Host 'Complete!' -ForegroundColor Cyan } else { Write-Host 'Expanding ...' -ForegroundColor Cyan & "$env:ProgramFiles\7-Zip\7z.exe" x -o"$ExpandedDriverPath" "$DownloadedDriverPath" -r ; } #=================================================================================================== # Verify Driver Expand #=================================================================================================== if (-not (Test-Path "$ExpandedDriverPath")) { Write-Warning "Driver Expand: Could not expand Driver to $ExpandedDriverPath ... Exiting" Break } $OSDDriver.OSDStatus = 'Expanded' #=================================================================================================== # PACK #=================================================================================================== if ($Pack.IsPresent) { #=================================================================================================== # Save-PnpOSDDriverPack #=================================================================================================== $OSDPnpClass = $OSDDriver.OSDPnpClass $OSDPnpFile = "$($DriverName).drvpnp" Write-Host "Save-PnpOSDDriverPack: Generating OSDDriverPNP (OSDPnpClass: $OSDPnpClass) ..." -ForegroundColor Gray Save-PnpOSDDriverPack -ExpandedDriverPath "$ExpandedDriverPath" $OSDPnpClass #=================================================================================================== # ExpandedDriverPath OSDDriver Objects #=================================================================================================== $OSDDriver | Export-Clixml -Path "$ExpandedDriverPath\OSDDriver.clixml" -Force $OSDDriver | ConvertTo-Json | Out-File -FilePath "$ExpandedDriverPath\OSDDriver.drvpack" -Force Publish-OSDDriverScripts -PublishPath "$PackagePath Test" New-Item "$PackagePath Test\$DriverGrouping" -ItemType Directory -Force | Out-Null Copy-Item "$ExpandedDriverPath\OSDDriver.drvpack" "$PackagePath Test\$DriverGrouping\$DriverName.drvpack" -Force Copy-Item "$ExpandedDriverPath\OSDDriver.drvpnp" "$PackagePath Test\$DriverGrouping\$DriverName.drvpnp" -Force Copy-Item "$ExpandedDriverPath\OSDDriver-Devices.csv" "$PackagePath Test\$DriverGrouping\$DriverName.csv" -Force Copy-Item "$ExpandedDriverPath\OSDDriver-Devices.txt" "$PackagePath Test\$DriverGrouping\$DriverName.txt" -Force #=================================================================================================== # Create Package #=================================================================================================== $PackagedDriverGroup = Get-PathOSDD -Path (Join-Path $PackagePath $DriverGrouping) Write-Verbose "PackagedDriverGroup: $PackagedDriverGroup" -Verbose Write-Verbose "PackagedDriverPath: $PackagedDriverPath" -Verbose if (Test-Path "$PackagedDriverPath") { #Write-Warning "Compress-OSDDriver: $PackagedDriverPath already exists" } else { New-CabFileOSDDriver -ExpandedDriverPath $ExpandedDriverPath -PublishPath $PackagedDriverGroup } Copy-Item "$ExpandedDriverPath\OSDDriver-Devices.csv" "$PackagePath\$DriverGrouping\$DriverName.csv" -Force Copy-Item "$ExpandedDriverPath\OSDDriver-Devices.txt" "$PackagePath\$DriverGrouping\$DriverName.txt" -Force #=================================================================================================== # Verify Driver Package #=================================================================================================== if (-not (Test-Path "$PackagedDriverPath")) { Write-Warning "Driver Package: Could not package Driver to $PackagedDriverPath ... Exiting" Continue } $OSDDriver.OSDStatus = 'Package' #=================================================================================================== # Export Results #=================================================================================================== $OSDDriver | Export-Clixml -Path "$ExpandedDriverPath\OSDDriver.clixml" -Force $OSDDriver | ConvertTo-Json | Out-File -FilePath "$ExpandedDriverPath\OSDDriver.drvpack" -Force $OSDDriver | ConvertTo-Json | Out-File -FilePath "$PackagedDriverGroup\$($DriverName).drvpack" -Force #=================================================================================================== # Export Files #=================================================================================================== #Write-Verbose "Verify: $ExpandedDriverPath\OSDDriver.drvpnp" if (Test-Path "$ExpandedDriverPath\OSDDriver.drvpnp") { Write-Verbose "Copy-Item: $ExpandedDriverPath\OSDDriver.drvpnp to $PackagedDriverGroup\$OSDPnpFile" Copy-Item -Path "$ExpandedDriverPath\OSDDriver.drvpnp" -Destination "$PackagedDriverGroup\$OSDPnpFile" -Force | Out-Null } $OSDDriver | Export-Clixml -Path "$ExpandedDriverPath\OSDDriver.clixml" -Force $OSDDriver | ConvertTo-Json | Out-File -FilePath "$ExpandedDriverPath\OSDDriver.drvpack" -Force $OSDDriver | ConvertTo-Json | Out-File -FilePath "$PackagedDriverGroup\$($DriverName).drvpack" -Force #=================================================================================================== # Publish-OSDDriverScripts #=================================================================================================== Publish-OSDDriverScripts -PublishPath $PackagedDriverGroup } } } End { #=================================================================================================== # Publish-OSDDriverScripts #=================================================================================================== Write-Host "Complete!" -ForegroundColor Green #=================================================================================================== } } |