Skip to content

Instantly share code, notes, and snippets.

@paitonic
Last active April 9, 2022 18:41
Show Gist options
  • Save paitonic/9b129d83a91918c935dd22f749631503 to your computer and use it in GitHub Desktop.
Save paitonic/9b129d83a91918c935dd22f749631503 to your computer and use it in GitHub Desktop.
function Get-Games {
# Game installation locations
$gameDirectoryNames = @("Genshin Impact", "Diablo II Resurrected")
return (
(Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common") +
(Get-ChildItem "C:\Program Files (x86)\GOG Galaxy\Games") +
(Get-ChildItem "C:\Program Files (x86)\Ubisoft\Ubisoft Game Launcher\games") +
(Get-ChildItem "C:\Program Files" | Where-Object { $gameDirectoryNames.Contains($_.Name) }) +
(Get-ChildItem "C:\Program Files (x86)" | Where-Object { $gameDirectoryNames.Contains($_.Name) })
)
}
function Format-Size {
param($Size)
if ($Size -lt 1GB) {
$value = [math]::Truncate($Size / 1MB)
return "$value MB"
} else {
$value = [math]::Truncate($Size / 1GB)
return "$value GB"
}
}
# returns content size of a directory in bytes
function Get-Size {
param($FullPath)
return (Get-ChildItem -Recurse -File -Path $FullPath | Measure-Object -Sum -Property Length).Sum
}
$items = @()
Get-Games | ForEach-Object {
$sizeInBytes = Get-Size -FullPath $_.FullName
$size = Format-Size -Size $sizeInBytes
$name = $_.Name
$path = $_.FullName
$items += @{
"Name" = $name;
"SizeInBytes" = $sizeInBytes;
"Size" = $size;
"Path" = $path
}
}
$items | ForEach-Object { [PSCustomObject]$_ } | Sort-Object -Property "SizeInBytes" -Desc | Format-Table -Property Name,Size
@paitonic
Copy link
Author

Output:

Name                                          Size  
----                                          ----
ForzaHorizon5                                 102 GB
Horizon Zero Dawn                             72 GB
GodOfWar                                      64 GB
Cyberpunk 2077                                61 GB

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