Last active
November 7, 2024 16:26
-
-
Save justinmarwad/9c36c7f9c622a6268adfe3618ef4af7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # IMPORTANT NOTE: This seems to only work with the Tesla Data Center driver 551.78. Source: https://www.reddit.com/r/PleX/comments/15ukivg/comment/lg0uxv9/. | |
| param ( | |
| [switch]$apply, | |
| [switch]$revert | |
| ) | |
| # Function to locate the correct registry path based on DriverDesc | |
| function Find-NVIDIARegistryPath { | |
| param ([string]$controlSet) | |
| $basePath = "HKLM:\SYSTEM\$controlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\" | |
| $maxAttempts = 10 # Adjust if you expect more than 5 entries (0000 - 0009) | |
| for ($i = 0; $i -lt $maxAttempts; $i++) { | |
| $subKeyPath = $basePath + "{0:D4}" -f $i | |
| if (Test-Path $subKeyPath) { | |
| $driverDesc = (Get-ItemProperty -Path $subKeyPath -Name "DriverDesc" -ErrorAction SilentlyContinue).DriverDesc | |
| if ($driverDesc -eq "NVIDIA Tesla P40") { | |
| return $subKeyPath | |
| } | |
| } else { | |
| break # Exit if subkey does not exist | |
| } | |
| } | |
| Write-Output "No NVIDIA Tesla P40 registry path found in $controlSet." | |
| return $null | |
| } | |
| # Function to apply registry modifications | |
| function Set-RegistryModifications { | |
| param ([string]$path) | |
| Set-ItemProperty -Path $path -Name "EnableMsHybrid" -Value 0x00000001 -Type DWord | |
| Set-ItemProperty -Path $path -Name "FeatureControl" -Value 0x00000004 -Type DWord | |
| Set-ItemProperty -Path $path -Name "FeatureScore" -Value 0x000000d1 -Type DWord | |
| Set-ItemProperty -Path $path -Name "GridLicensedFeatures" -Value 0x00000007 -Type DWord | |
| Set-ItemProperty -Path $path -Name "AdapterType" -Value 0x00000001 -Type DWord | |
| Write-Output "Registry modifications applied successfully at $path." | |
| } | |
| # Function to revert registry to original settings | |
| function Revert-RegistryModifications { | |
| param ([string]$path) | |
| if (Test-Path "$path\EnableMsHybrid") { Remove-ItemProperty -Path $path -Name "EnableMsHybrid" } | |
| Set-ItemProperty -Path $path -Name "FeatureControl" -Value 0x00000004 -Type DWord | |
| Set-ItemProperty -Path $path -Name "FeatureScore" -Value 0x000000cf -Type DWord | |
| if (Test-Path "$path\GridLicensedFeatures") { Remove-ItemProperty -Path $path -Name "GridLicensedFeatures" } | |
| Set-ItemProperty -Path $path -Name "AdapterType" -Value 0x00000002 -Type DWord | |
| Write-Output "Registry reverted to original settings at $path." | |
| } | |
| # Function to restart the NVIDIA Tesla P40 display adapter | |
| function Restart-NVIDIAAdapter { | |
| # Find the NVIDIA Tesla P40 adapter and get its InstanceId | |
| $adapter = Get-PnpDevice -FriendlyName "NVIDIA Tesla P40" -ErrorAction SilentlyContinue | |
| if ($null -eq $adapter) { | |
| Write-Output "NVIDIA Tesla P40 adapter not found." | |
| return | |
| } | |
| # Disable the display adapter | |
| Disable-PnpDevice -InstanceId $adapter.InstanceId -Confirm:$false | |
| Write-Output "Display adapter disabled." | |
| # Wait for 5 seconds | |
| Start-Sleep -Seconds 5 | |
| # Enable the display adapter | |
| Enable-PnpDevice -InstanceId $adapter.InstanceId -Confirm:$false | |
| Write-Output "Display adapter enabled." | |
| } | |
| # Main logic to handle both CurrentControlSet and ControlSet001 | |
| $controlSets = @("CurrentControlSet", "ControlSet001") | |
| $registryPaths = @() | |
| foreach ($controlSet in $controlSets) { | |
| $registryPath = Find-NVIDIARegistryPath -controlSet $controlSet | |
| if ($registryPath) { | |
| $registryPaths += $registryPath | |
| } | |
| } | |
| if ($registryPaths.Count -eq 0) { | |
| Write-Output "NVIDIA Tesla P40 device not found in any control set. Exiting script." | |
| exit | |
| } | |
| # Check CLI arguments and apply/revert changes to all found paths | |
| if ($apply.IsPresent -and $revert.IsPresent) { | |
| Write-Output "Please specify only one of the arguments: --apply or --revert." | |
| } elseif ($apply.IsPresent) { | |
| foreach ($path in $registryPaths) { | |
| Set-RegistryModifications -path $path | |
| } | |
| Restart-NVIDIAAdapter # Restart the adapter after applying modifications | |
| } elseif ($revert.IsPresent) { | |
| foreach ($path in $registryPaths) { | |
| Revert-RegistryModifications -path $path | |
| } | |
| } else { | |
| Write-Output "Usage: script.ps1 --apply or --revert" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment