Created
September 10, 2019 14:28
-
-
Save opariffazman/04a120f10222e2b9bc141ef0c602f079 to your computer and use it in GitHub Desktop.
Run Installed Steam Game from Powershell
This file contains 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 steam-run { | |
param( | |
[Parameter(Mandatory = $false)][string]$Name | |
) | |
# steam installed directory containing the .acf files | |
# replace with your path here | |
$steamInstalledPath = "C:\Users\opari\scoop\apps\steam\current\steamapps" | |
# run by game name specified | |
if ($Name) { | |
$acf = Get-ChildItem $steamInstalledPath | Select-String -Pattern $Name | Select-Object Filename -First 1 | |
$steamGameRaw = Get-ChildItem $steamInstalledPath | Select-String -Pattern 'name' | Select-String -Pattern $Name | ForEach-Object line | |
$steamGame = $steamGameRaw -replace "`"|name", '' | ForEach-Object { $_.trim() } | |
} | |
else { | |
# display list of game if no argument specified | |
$count = 1 | |
$steamInstalledGameRaw = Get-ChildItem $steamInstalledPath | Where-Object {$_.Name -match '.acf' -and $_.Name -ne 'appmanifest_228980.acf' } | Select-String -Pattern 'name' | ForEach-Object line | |
$steamInstalledGame = $steamInstalledGameRaw -replace "`"|name", '' | ForEach-Object { | |
"[$count] $($_.trim())" | |
$count++ | |
} | |
Write-Output "==============================" | |
Write-Output $steamInstalledGame | |
Write-Output "==============================" | |
# run by game list selection | |
do { | |
try { | |
$numOk = $true | |
[int]$selection = Read-Host -Prompt "Enter Selection" | |
} | |
catch { | |
$numOK = $false | |
} | |
} | |
until (($selection -ge 1 -and $selection -lt $count) -and $numOK) | |
$acf = Get-ChildItem $steamInstalledPath | Select-String -Pattern $steamInstalledGameRaw[$selection] | Select-Object Filename -First 1 | |
$steamGame = $steamInstalledGameRaw[$selection] -replace "`"|name", '' | ForEach-Object { $_.trim() } | |
} | |
if ($acf) { | |
Write-Verbose -Message "Running $steamGame" -Verbose | |
$gameId = $acf.Filename -replace "[^0-9]" , '' | |
Start-Process steam://rungameid/$gameId | |
} | |
else { | |
Write-Warning -Message "Steam Game Not Installed" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment