<# This script will add the NVIDIA Control Panel Appx Package References: - https://www.vjonathan.com/post/dem-non-persistent-vdi-deployment-and-nvidia-control-panel-missing/ - https://www.jhouseconsulting.com/jhouseconsulting/2024/07/14/restoring-the-nvidia-control-panel-and-tools-after-the-appx-package-change-2903 We get the PackageFullName value for the Appx Package from the "HKEY_LOCAL_MACHINE\SOFTWARE\NVIDIA Corporation\NVControlPanelAppXInformation" registry key. This is set as a post install part of the driver installation process. Accept the NVIDIA Control Panel EULA Key: HKEY_CURRENT_USER\SOFTWARE\NVIDIA Corporation\NVControlPanel2\Client Type: REG_DWORD Value: ShowSedoanEula Data: 1 Add NVIDIA Control Panel to the Desktop Context Menu Key: HKEY_CURRENT_USER\SOFTWARE\NVIDIA Corporation\Global\NvCplApi\Policies Type: REG_DWORD Value: ContextUIPolicy Data: 2 Script name: Add-NVIDIA_Control_Panel.ps1 Release 1.0 Written by Jeremy Saunders (jeremy@jhouseconsulting.com) 6th May 2024 #> #------------------------------------------------------------- # Set Powershell Compatibility Mode Set-StrictMode -Version 2.0 # Enable verbose, warning and error mode $VerbosePreference = 'Continue' $WarningPreference = 'Continue' $ErrorPreference = 'Continue' #------------------------------------------------------------- $StartDTM = (Get-Date) # Set the working folder to the users TEMP folder $LogFolder = [System.IO.Path]::GetTempPath() # Get the script name $ScriptName = [System.IO.Path]::GetFilenameWithoutExtension($MyInvocation.MyCommand.Path.ToString()) # Start the transcript try { Start-Transcript "$LogFolder$ScriptName.log" } catch { write-verbose "$(Get-Date): This host does not support transcription" } #------------------------------------------------------------- # The DCH (Declarative Componentized Hardware) driver model started from GRID 15.0 (527.41) [float]$StartingVersion = 527.41 #------------------------------------------------------------- Function Create-RegKey { param ( [String]$Path ) $KeyExists = $False $ErrorActionPreference = "stop" try { Get-Item -Path "$Path" | Out-Null $KeyExists = $true } catch { # } $ErrorActionPreference = "Continue" If ($KeyExists -eq $False) { write-verbose "Creating the `"$Path`" registry key" -verbose New-Item -Path "$path" -Force | Out-Null } } Function Create-RegValue { param ( [String]$Path, [String]$Value, [String]$Data, [String]$Type ) $ValueExists = $False $ErrorActionPreference = "stop" try { If ((Get-ItemProperty -Path "$Path" | Select-Object -ExpandProperty "$Value") -ne $null) { $ValueExists = $True } } catch { # } $ErrorActionPreference = "Continue" If ($ValueExists) { write-verbose "- Setting the $Value registry value" -verbose Set-ItemProperty -Path "$Path" -Name "$Value" -Type $Type -Value $Data –Force } Else { write-verbose "- Creating the $Value registry value" -verbose New-ItemProperty -Path "$Path" -Name "$Value" -PropertyType $Type -Value $Data | Out-Null } } #------------------------------------------------------------- $PackageFullName = "" $ErrorActionPreference = "stop" Try { $PackageFullName = (Get-ItemProperty -Path "HKLM:\SOFTWARE\NVIDIA Corporation\NVControlPanelAppXInformation" -Name PackageFullName).PackageFullName } Catch [System.Exception]{ write-warning "$($Error[0].Exception.Message)" -verbose } $ErrorActionPreference = "Continue" [float]$DriverVersion = 0.00 Try { If (TEST-PATH "${env:SystemRoot}\System32\nvidia-smi.exe") { $DriverVersion = & "${env:SystemRoot}\System32\nvidia-smi.exe" --query-gpu=driver_version --format=csv,noheader } } Catch [System.Exception]{ write-warning "$($Error[0].Exception.Message)" -verbose } If ($DriverVersion -ge $StartingVersion) { write-verbose "Driver $($DriverVersion.ToString()) is a DCH (Declarative Componentized Hardware) driver and uses the Control Panel Appx Package" -verbose If (!([String]::IsNullOrEmpty($PackageFullName))) { Try { write-verbose "Registering the existing NVIDIA Control Panel Appx Package from the `"${env:ProgramFiles}\WindowsApps\$PackageFullName$PackageFullName`" folder" -verbose Add-AppxPackage -Register "${env:ProgramFiles}\WindowsApps\$PackageFullName\AppxManifest.xml" -DisableDevelopmentMode } Catch [System.Exception]{ write-warning "$($Error[0].Exception.Message)" -verbose } } Else { write-warning "Unable to register the NVIDIA Control Panel Appx Package because the PackageFullName was not set." -verbose } } #------------------------------------------------------------- # Accept the NVIDIA Control Panel EULA Create-RegKey -Path:"HKCU:\SOFTWARE\NVIDIA Corporation\NVControlPanel2\Client" Create-RegValue -Path:"HKCU:\SOFTWARE\NVIDIA Corporation\NVControlPanel2\Client" -Value:"ShowSedoanEula" -Data:1 -Type:DWORD # Add NVIDIA Control Panel to the Desktop Context Menu Create-RegKey -Path:"HKCU:\SOFTWARE\NVIDIA Corporation\Global\NvCplApi\Policies" Create-RegValue -Path:"HKCU:\SOFTWARE\NVIDIA Corporation\Global\NvCplApi\Policies" -Value:"ContextUIPolicy" -Data:2 -Type:DWORD #------------------------------------------------------------- Write-Verbose "Stop logging" -Verbose $EndDTM = (Get-Date) Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalSeconds) Seconds" -Verbose Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalMinutes) Minutes" -Verbose # Stop the transcript try { Stop-Transcript } catch { write-verbose "$(Get-Date): This host does not support transcription" }