Last active
May 4, 2026 08:25
-
-
Save spddl/d468279dc4853c3995646615576b7669 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
| Function Get-FileSize { | |
| Param( | |
| [int64]$length | |
| ) | |
| If ($length -ge 1TB) { | |
| return '{0:N2} TB' -f ($length / 1TB) | |
| } elseif ($length -ge 1GB) { | |
| return '{0:N2} GB' -f ($length / 1GB) | |
| } elseif ($length -ge 1MB) { | |
| return '{0:N2} MB' -f ($length / 1MB) | |
| } elseif ($length -ge 1KB) { | |
| return '{0:N2} KB' -f ($length / 1KB) | |
| } else { | |
| return "$length bytes" | |
| } | |
| } | |
| Function Clear-Folder { | |
| Param( | |
| [string]$path | |
| ) | |
| if (-Not (Test-Path -Path $path)) { | |
| $nul = Get-FileSize(0) | |
| return [pscustomobject]@{path = $path; 'before cleaning' = $nul; afterwards = $nul; deleted = $nul } | |
| } | |
| [int64]$beforeLength = 0 | |
| Get-ChildItem -Path $path -Recurse -Force | ForEach-Object { | |
| $beforeLength += $_.Length | |
| Unblock-File $_.FullName | |
| } | |
| If ($beforeLength -eq 0) { | |
| $nul = Get-FileSize(0) | |
| return [pscustomobject]@{path = $path; 'before cleaning' = $nul; afterwards = $nul; deleted = $nul } | |
| } | |
| Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue | |
| [int64]$afterwardsLength = 0 | |
| Get-ChildItem -Path $path -Recurse -Force | ForEach-Object { | |
| $afterwardsLength += $_.Length | |
| } | |
| [pscustomobject]@{path = $path; 'before cleaning' = Get-FileSize($beforeLength); afterwards = Get-FileSize($afterwardsLength); deleted = Get-FileSize($beforeLength - $afterwardsLength) } | |
| } | |
| Function Clear-Files { | |
| Param( | |
| [string]$path | |
| ) | |
| [int64]$beforeLength = 0 | |
| Get-ChildItem -Path $path -Force -ErrorAction SilentlyContinue | ForEach-Object { | |
| $beforeLength += $_.Length | |
| Unblock-File $_.FullName | |
| Remove-Item -LiteralPath $_.FullName -Force -ErrorAction SilentlyContinue | |
| } | |
| If ($beforeLength -eq 0) { | |
| $nul = Get-FileSize(0) | |
| return [pscustomobject]@{path = $path; 'before cleaning' = $nul; afterwards = $nul; deleted = $nul } | |
| } | |
| Remove-Item -Path $path -Force -ErrorAction SilentlyContinue | |
| [int64]$afterwardsLength = 0 | |
| Get-ChildItem -Path $path -Force | ForEach-Object { | |
| $afterwardsLength += $_.Length | |
| } | |
| [pscustomobject]@{path = $path; 'before cleaning' = Get-FileSize($beforeLength); afterwards = Get-FileSize($afterwardsLength); deleted = Get-FileSize($beforeLength - $afterwardsLength) } | |
| } | |
| $SteamPath = (Get-ItemProperty -Path HKCU:\SOFTWARE\Valve\Steam -Name SteamPath).SteamPath | |
| $libraryfolders = [IO.Path]::Combine($SteamPath , 'steamapps', 'libraryfolders.vdf') | |
| $path = '' | |
| $SteamFolder = Get-Content $libraryfolders | ForEach-Object { | |
| if ($_ -match '("path").*"(.+)"') { | |
| $path = $Matches[2] | |
| } | |
| if ($_ -match '("730").*"(.+)"') { | |
| return $path | Resolve-Path | |
| } | |
| } | |
| $csgoFolder = [IO.Path]::Combine($SteamFolder, 'steamapps', 'common', 'Counter-Strike Global Offensive') | |
| Get-ChildItem -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches -Exclude 'Device Driver Packages' | ForEach-Object { | |
| if ($_.Property -NotContains 'StateFlags') { | |
| return | |
| } | |
| if ($_.Property -NotContains 'StateFlags1337') { | |
| if ($_.PSChildName -eq 'D3D Shader Cache') { | |
| New-ItemProperty -Path $_.PSPath -Name 'StateFlags1337' -Value '2' -PropertyType DWord | Out-Null | |
| } else { | |
| New-ItemProperty -Path $_.PSPath -Name 'StateFlags1337' -Value '0' -PropertyType DWord | Out-Null | |
| } | |
| } | |
| } | |
| ######## | |
| @( | |
| Clear-Folder("\\?\C:\Users\$env:UserName\AppData\LocalLow\NVIDIA\PerDriverVersion\DXCache") | |
| Clear-Folder("\\?\C:\Users\$env:UserName\AppData\Local\NVIDIA\GLCache") | |
| Clear-Folder("\\?\C:\Users\$env:UserName\AppData\Local\Steam\htmlcache\Default\Cache") | |
| Clear-Folder("\\?\C:\Users\$env:UserName\AppData\Local\AMD\GLCache") | |
| Clear-Folder("\\?\$env:APPDATA\NVIDIA\ComputeCache") | |
| Clear-Folder("\\?\C:\Program Files (x86)\Steam\appcache\httpcache") | |
| Clear-Folder("\\?\C:\Program Files (x86)\Steam\appcache\librarycache") | |
| Clear-Folder("\\?\C:\Program Files (x86)\Steam\depotcache") | |
| Clear-Folder("\\?\C:\Program Files (x86)\Steam\steamapps\shadercache\730") | |
| Clear-Files("\\?\C:\Program Files (x86)\Steam\dumps\*.*") | |
| Clear-Files("\\?\$csgoFolder\game\bin\win64\*.mdmp") | |
| Clear-Files("\\?\$csgoFolder\game\csgo\*.txt") | |
| Clear-Files("\\?\$csgoFolder\game\csgo\*.log") | |
| Clear-Files("\\?\$csgoFolder\game\csgo\_iconcache\*.iic") | |
| ) | Format-Table -Wrap | |
| # delete the DirectX Shader Cache | |
| # https://learn.microsoft.com/de-de/troubleshoot/windows-server/backup-and-storage/automating-disk-cleanup-tool#registry-key-information | |
| Start-Process -FilePath cleanmgr.exe -ArgumentList '/sagerun:1337' | |
| Read-Host -Prompt "Verify integrity of game files?" | |
| Start-Process -FilePath 'steam://validate/730' | |
| Pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment