Last active
April 9, 2022 18:41
-
-
Save paitonic/9b129d83a91918c935dd22f749631503 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-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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: