cEPRSInstallTFS2015.psm1

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
59
60
61
62
63
64
65
66
67
68
69

[DSCResource()]

class cEPRSInstallTFS2015
{
    [DSCProperty(Key)] [String] $TFSInstallerPath
    [DSCProperty(Key)] [String] $Server

   
    [cEPRSInstallTFS2015] Get()
    {
        $config = @{TFSInstallerPath = $this.TFSInstallerPath; }  
        return $config
    }
    
    [bool] Test()
    {
        if (!(Test-Path $this.TFSInstallerPath))
        {
            return $true
        }
        else
        {
            return $false
        }
    }

    [void] Set()
    {
        $Installer = $this.TFSInstallerPath
        $ServerName = $this.Server
        Install $Installer $ServerName
    } 

}
Function Install
{
 param(
        [string] $TFSInstaller,
        [string] $ServerName
        #[System.Management.Automation.PSCredential] $Credential
    )

    Write-Verbose "Path: $TFSInstaller; ServerName- $ServerName" -Verbose
    
    if (!(Test-Path $TFSInstaller))
    {
        Write-Verbose ("Setup file not found") -Verbose
    }
        $Credential = New-Object System.Management.Automation.PSCredential ("$Username", $password)
        Robocopy $TFSInstaller "$ServerName\C$\TFS2015" /E 
        $ps = New-PSSession -ComputerName $ServerName  -Credential $Credential
        Invoke-Command -Session $ps -ScriptBlock {
    
        $proc= Start-Process "C:\TFS2015\tfs_server.exe" -ArgumentList "/noweb /q /norestart /log $env:TEMP\TFS2015\TFSlog.txt" -Wait -NoNewWindow
        Write-Verbose "Ended $($proc.ExitCode) " -verbose

    if ($proc.HasExited)
    {
        Write-Verbose ":: Installation process exited, logging provided at " -Verbose
        switch ($($proc.ExitCode))
        { 
            0 {Write-Verbose "TFS was installed successfully." -Verbose }
            default {throw ("An error occured with return code $($proc.ExitCode).")}
        }  
    }
    }
    Remove-PSSession $ps
}