Skip to content

Instantly share code, notes, and snippets.

@jamesy0ung
Created December 3, 2024 22:28
Show Gist options
  • Save jamesy0ung/b187b022c9bf7a6dde30f4b14fa50d72 to your computer and use it in GitHub Desktop.
Save jamesy0ung/b187b022c9bf7a6dde30f4b14fa50d72 to your computer and use it in GitHub Desktop.
# Ensure the script is running as Administrator
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Output "Please run this script as an Administrator!"
Exit
}
# Define the registry paths to clean
$graphicsDriversPath = "HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers"
$subKeys = @("Configuration", "Connectivity", "ScaleFactors")
# Delete the profiles under each subkey
foreach ($subKey in $subKeys) {
$fullPath = Join-Path $graphicsDriversPath $subKey
if (Test-Path $fullPath) {
Get-ChildItem $fullPath | ForEach-Object {
Remove-Item -Path $_.PSPath -Recurse -Force
}
Write-Output "Cleared $subKey under GraphicsDrivers."
} else {
Write-Output "$subKey does not exist or has already been cleared."
}
}
Write-Output "Display cache cleared. Please restart your computer for changes to take effect."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment