├── README.md └── Steam.psm1 /README.md: -------------------------------------------------------------------------------- 1 | Steam-Management-for-PowerShell 2 | =============================== 3 | 4 | This is a PowerShell module which helps you manage Steam games by offering the ability to move games to other locations in your file system, such as from your HDD to your SSD. 5 | 6 | Note that this only allows you to operate on games installed in the steamapps\common folder, and thus does not support most Source games. 7 | If you'd like to add support for other games, please feel free to fork! 8 | 9 | To import this module, run: 10 | 11 | ``` 12 | PS C:\> Import-Module Steam.psm1 13 | ``` 14 | 15 | or add the module to \My Documents\WindowsPowerShell\Steam\Steam.psm1 16 | 17 | Run Get-SteamGame to get a list of currently installed Steam Games. 18 | 19 | ``` 20 | PS C:\> Get-SteamGame 21 | 22 | Directory: E:\program files\steam\steamapps\common 23 | 24 | 25 | Mode LastWriteTime Length Name 26 | ---- ------------- ------ ---- 27 | d---- 2/15/2013 7:29 Age Of Empires 3 28 | d---- 4/11/2013 17:43 Age2HD 29 | d---- 8/16/2012 4:44 amnesia the dark descent 30 | d---- 8/16/2012 19:14 and yet it moves 31 | d---- 8/16/2012 19:13 Aquaria 32 | d---- 9/15/2012 1:27 assassin's creed 2 33 | d---- 1/18/2013 22:24 assassin's creed revelations 34 | ... 35 | ``` 36 | 37 | Use Move-SteamGame to move Steam Games. Use -Game to specify the name of the game and -Destination to specify the directory to be moved to. 38 | Note that the name of the game must match that show in the Get-SteamGame command, which is essentially the game's Steam directory. 39 | 40 | Note that you must have Admin access to use this command. 41 | 42 | ``` 43 | PS C:\WINDOWS\system32> Move-SteamGame -Game Age2HD -Destination 'C:\Steam Games' 44 | ``` 45 | 46 | Specify the -Moved switch on Get-SteamGame to see exclusively those games that have been moved from their original directory. 47 | 48 | ``` 49 | PS C:\WINDOWS\system32> Get-SteamGame -Moved 50 | 51 | 52 | Directory: C:\Steam Games 53 | 54 | 55 | Mode LastWriteTime Length Name 56 | ---- ------------- ------ ---- 57 | d---- 4/17/2013 1:47 Age2HD 58 | 59 | ``` 60 | 61 | Conversely, using the -NotMoved switch will show only those games that haven't been moved. 62 | 63 | If you'd like to restore a steam game, just run Restore-SteamGame. 64 | 65 | ``` 66 | PS C:\WINDOWS\system32> Restore-SteamGame Age2HD 67 | ``` 68 | 69 | Again, this requires admin. 70 | 71 | Please leave feedback! -------------------------------------------------------------------------------- /Steam.psm1: -------------------------------------------------------------------------------- 1 | $steamAppsDir = (Get-Item HKCU:\Software\Valve\Steam).GetValue("SteamPath") + "/steamapps/common/" 2 | 3 | $gameLocPattern = [regex]"\s*(?.*)\[(?.*)\]$" 4 | 5 | $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") 6 | 7 | function Get-SteamGame 8 | { 9 | param( 10 | [Switch]$Moved, 11 | [Switch]$NotMoved 12 | ) 13 | 14 | $apps = Get-ChildItem $steamAppsDir 15 | 16 | if(-Not $Moved -and -not $NotMoved) 17 | { 18 | $Moved = $true 19 | $NotMoved = $true 20 | } 21 | 22 | if($Moved) 23 | { 24 | $output = cmd /c dir $steamAppsDir /A:L 25 | 26 | $output = @($output | where { ($gameLocPattern.Match($_)).Success }) 27 | 28 | for($i = 0; $i -lt $output.Length; $i++) 29 | { 30 | $match = $gameLocPattern.Match($output[$i]) 31 | $name = $match.Groups["Game"].Value.Trim() 32 | $location = $match.Groups["Location"].Value.Trim() 33 | 34 | Get-Item $location 35 | } 36 | } 37 | 38 | if($NotMoved) 39 | { 40 | $apps | where { !($_.Attributes.ToString().Contains("ReparsePoint")) } 41 | } 42 | } 43 | 44 | function Move-SteamGame 45 | { 46 | param( 47 | [Parameter(Position=0,Mandatory=$true)] 48 | [String]$Game, 49 | 50 | [Parameter(Position=1,Mandatory=$true)] 51 | [String]$Destination 52 | ) 53 | 54 | if($Host.Version.Major -lt 3) 55 | { 56 | Write-Error "This script requires PowerShell 3.0+" 57 | Break 58 | } 59 | 60 | If (-Not $isAdmin) 61 | { 62 | Write-Warning "This script requires Admin." 63 | Break 64 | } 65 | 66 | $availableGames = Get-SteamGame -NotMoved 67 | $gameNames = $availableGames | select { $_.Name } 68 | 69 | if(-Not ($availableGames.Name -contains $Game)) 70 | { 71 | Write-Warning "Your requested game `"$Game`" was unavailable. Please use one of the following:" 72 | $availableGames 73 | break 74 | } 75 | 76 | $gameFolder = $availableGames | where { $_.Name -eq $Game } 77 | 78 | $DestinationPath = $Destination + "\" + $gameFolder.Name 79 | 80 | $ErrorActionPreference = "SilentlyContinue" 81 | 82 | $item = Get-Item $DestinationPath -ErrorVariable $getError 83 | 84 | $exists = ($item -ne $null) 85 | 86 | $ErrorActionPreference = "Stop" 87 | 88 | if(-Not $exists) 89 | { 90 | Write-Progress -Activity "Moving $Game to $DestinationPath" -Status "Copying. Please be patient." -CurrentOperation "Moving Game" 91 | Move-Item -Path $gameFolder.FullName -Destination $Destination 92 | 93 | cmd /c mklink /D $gameFolder.FullName $DestinationPath 94 | } 95 | else 96 | { 97 | Write-Warning "The game already exists at $Destination." 98 | } 99 | } 100 | 101 | function Restore-SteamGame 102 | { 103 | param( 104 | [Parameter(Position=0,Mandatory=$true)] 105 | [String]$Game 106 | ) 107 | 108 | if($Host.Version.Major -lt 3) 109 | { 110 | Write-Error "This script requires PowerShell 3.0+" 111 | Break 112 | } 113 | 114 | If (-Not $isAdmin) 115 | { 116 | Write-Warning "This script requires Admin." 117 | Break 118 | } 119 | 120 | $availableGames = Get-SteamGame -Moved 121 | 122 | if(-Not ($availableGames.Name -contains $Game)) 123 | { 124 | Write-Warning "Your requested game `"$Game`" was unavailable. Please use one of the following:" 125 | $availableGames 126 | break 127 | } 128 | 129 | $steamGameDir = $steamAppsDir + $Game 130 | 131 | Write-Progress -Activity "Moving $Game to $steamGameDir" -Status "Copying. Please be patient." -CurrentOperation "Moving Game" 132 | 133 | cmd /c rmdir $steamGameDir 134 | 135 | $item = $availableGames | where { $_.Name -eq $Game } 136 | Move-Item -Path $item.FullName -Destination $steamGameDir 137 | } --------------------------------------------------------------------------------