Skip to content

Instantly share code, notes, and snippets.

@roose
Last active October 6, 2023 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roose/a8eb195afcfe1639802baa109b1330e5 to your computer and use it in GitHub Desktop.
Save roose/a8eb195afcfe1639802baa109b1330e5 to your computer and use it in GitHub Desktop.
Repairing Steam Desktop Icons
$cdnUrl = "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/"
$steamFolder = (Get-Item HKCU:\Software\Valve\Steam).GetValue("SteamPath") + "/steam/games/"
# $steamFolder = "C:/Program Files (x86)/Steam/steam/games"
$desktopPath = [Environment]::GetFolderPath("Desktop")
$currentDirectory = $PWD
# Check if we have write access to $steamFolder
if (Test-Path -Path $steamFolder) {
try {
$testFile = Join-Path -Path $steamFolder -ChildPath "test.txt"
"Write test" | Out-File -FilePath $testFile -Force
Remove-Item -Path $testFile -Force
} catch {
# If we can't write to $steamFolder, request admin rights
Start-Process powershell -Verb runAs -ArgumentList "-NoProfile -c cd '$currentDirectory'; .\getsteamicons.ps1"
exit
}
}
# Get all .url files
$urlFiles = Get-ChildItem -Path $desktopPath -Filter *.url
# Walk through all .url files
foreach ($urlFile in $urlFiles) {
# Read content of .url
$urlContent = Get-Content -Path $urlFile.FullName
# Create hash table for appID and iconFile
$urlData = @{}
# if it is steam game link
if ($urlContent -match "steam://rungameid") {
# Walk through all lines in .url
foreach ($line in $urlContent) {
if ($line -match '^\s*([^=]+)\s*=\s*(.+)') {
$key = $Matches[1].Trim()
$value = $Matches[2].Trim()
# Extract appID and iconFile
if ($key -eq "URL") {
$urlData["appID"] = $value.Split("/")[-1]
}
if ($key -eq "IconFile") {
$urlData["iconFile"] = (Split-Path -Path $value -Leaf)
}
}
}
$appID = $urlData['appID']
$iconFile = $urlData['iconFile']
Write-Host "Downloading icon for $($urlFile.Name)..."
Invoke-WebRequest -Uri "$cdnUrl$appID/$iconFile" -OutFile "$steamFolder/$iconFile"
Write-Host "...done."
}
}
Read-Host "Please press Enter to exit"
@roose
Copy link
Author

roose commented Oct 5, 2023

You may need to run Set-ExecutionPolicy RemoteSigned first if it's your first time running a PowerShell script.

  1. Click on Raw.
  2. Save the file as getsteamicons.ps1.
  3. Right-click on getsteamicons.ps1 in Explorer.
  4. Select "Run with PowerShell."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment