cEPRSInstallTFS2015.psm1


[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
}