Public/Install-SteamCMD.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function Install-SteamCMD {
    <#
    .SYNOPSIS
    Install SteamCMD.
 
    .DESCRIPTION
    This cmdlet downloads SteamCMD and configures it in any desired folders.
 
    .PARAMETER InstallPath
    Specifiy the location of SteamCMD. Default is C:\SteamCMD.
 
    .EXAMPLE
    An example
 
    .NOTES
    General notes
    #>


    [CmdletBinding()]
    param (
        [parameter(Mandatory = $false)]
        [string]$InstallPath = 'C:\SteamCMD'
    )

    begin {
        $TempDirectory = 'C:\Temp'
        if (-not (Test-Path -Path $TempDirectory)) {
            Write-Verbose -Message 'Creating Temp directory.'
            New-Item -Path 'C:\' -Name 'Temp' -ItemType Directory | Write-Verbose
        }
    }

    process {
        # Download SteamCMD.
        Invoke-WebRequest -Uri 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip' -OutFile "$($TempDirectory)\steamcmd.zip" -UseBasicParsing

        # Create SteamCMD directory in C:\ if necessary.
        if (-not (Test-Path -Path $InstallPath)) {
            Write-Verbose -Message "Creating SteamCMD directory: $($InstallPath)"
            New-Item -Path $InstallPath -ItemType Directory | Write-Verbose
            Expand-Archive -Path "$($TempDirectory)\steamcmd.zip" -DestinationPath $InstallPath
        }

        # Doing some initial configuration of SteamCMD. The first time SteamCMD is launched it will need to do some updates.
        Write-Host -Object 'Setting up SteamCMD for the first time. Please wait.' -NoNewline
        Start-Process -FilePath $InstallPath\steamcmd.exe -ArgumentList 'validate +quit' -WindowStyle Hidden
        do {
            Write-Host -Object "." -NoNewline
            Start-Sleep -Seconds 3
        }
        until (-not (Get-Process -Name "*steamcmd*"))
    }

    end {
        Remove-Item -Path "$($TempDirectory)\steamcmd.zip"
    }
}