Instal_edeiaLab.psm1


<#
.Synopsis
   Instalar e-DeiaLab em um terminal
.DESCRIPTION
   Este modulo instalada o e-DeiaLab num terminal juntamente com todas as ferramentas necessárias
.EXAMPLE
   get-eDeiaLab -DrDestino c:\edeia -Servidor=192.168.1.1
.EXAMPLE
   get-eDeiaLab -DrDestino c:\edeia -Servidor=Servidor
#>

function get-eDeiaLab
{
    [CmdletBinding()]
    Param
    (
        # Diretorio local onde sera instalado e-DeiaLab c:\edeia
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        $DirDestino="c:\edeiax",
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=1)]
        # IP ou DNS do servidor onde está o e-DeiaLab
        $Servidor="192.168.111.3"
    )

    Begin
    {
    }
    Process
    {
    

            #$DirDestino="c:\edeiax"
            #$Servidor="192.168.111.3"



            # testar se existe o diretorio e se não criar

            if (-not(Test-Path -Path $DirDestino))
            {
                New-Item -Path $DirDestino -ItemType Directory
            }

            # descarregar o necessário do servidor cliente ou remoto

            $filelocal="menulab.exe"
            Start-BitsTransfer -Source "http://$servidor/edeia/$filelocal" -Destination "$DirDestino\$filelocal"

            $fileremoto="syncfusion.tools.dll", "Syncfusion.Grid.dll", "Syncfusion.Shared.dll", "Menulab.xml"
            foreach ($f in $fileremoto)
            {
                Start-BitsTransfer -Source "http://192.168.111.1/edeia/tools/InstalacaoLocal/$f" -Destination "$DirDestino\$f"
                #Write-Output "http://192.168.111.1/edeia/tools/InstalacaoLocal/$f"
            }

            #abrir o menulab.xml para definir o servidor
            $fileMenulab_xml="$DirDestino\menulab.xml"

            if (Test-Path -Path $fileMenulab_xml)
            {
                [xml]$XmlDocument = Get-Content -Path $fileMenulab_xml
            }

            $XmlDocument.Configuracao.UrlServidor="http://$Servidor/edeia/"
            $XmlDocument.Save($fileMenulab_xml)

            #testar se 64 se 32
            $32_ou_64=(Get-WmiObject Win32_OperatingSystem).OSArchitecture

            #Instalar o .net4.0

            $f="dotNetFx40_Full_x86_x64.exe"
            if (-not (Test-Path -Path  "$DirDestino\$f"))
            {
                Start-BitsTransfer -Source "http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/$f" -Destination "$DirDestino\$f" 
            }
            Start-Process -FilePath "$DirDestino\$f" -ArgumentList "/q /norestart" -wait
            $f=""

            #instalar o crystal
            if ( $32_ou_64.StartsWith("64"))
            {
                #instalar 64 bits

                $fileremoto="Crystal_V10.x64.msi", "CRRuntime_64bit_13_0_8.msi"
                foreach ($f in $fileremoto)
                {   
                    if (-not (Test-Path -Path  "$DirDestino\$f"))
                    {
                        Start-BitsTransfer -Source "http://192.168.111.1/edeia/tools/InstalacaoLocal/$f" -Destination "$DirDestino\$f"           
                    }
                    #Write-Output "http://192.168.111.1/edeia/tools/InstalacaoLocal/$f"
                    # deploy Crystal Reports
                    Start-Process "$DirDestino\$f" /qn -Wait -Verbose
                }
            }
            else
            {
                 #instalar 32 bits
                $fileremoto="Crystal_V10.x86.msi", "CRRuntime_32bit_13_0_8.msi"
                foreach ($f in $fileremoto)
                {  
                    if (-not (Test-Path -Path  "$DirDestino\$f"))
                        {  

                            Start-BitsTransfer -Source "http://192.168.111.1/edeia/tools/InstalacaoLocal/$f" -Destination "$DirDestino\$f" 
                
                        }
                    # deploy Crystal Reports
                    Start-Process "$DirDestino\$f" /qn -Wait -Verbose
                }
            }

            #Criar atalho ambiente de trabalho
            $WshShell = New-Object -comObject WScript.Shell
            $Shortcut = $WshShell.CreateShortcut("$Home\Desktop\e-DeiaLab.lnk")
            $Shortcut.TargetPath = "$DirDestino\menulab.exe"
            $Shortcut.Save()


            #copiar fonte cod-39
            $f="Code-39-20.ttf"
            Start-BitsTransfer -Source "http://192.168.111.1/edeia/tools/InstalacaoLocal/$f" -Destination "$DirDestino\$f" 

            if (-not(Test-Path -Path "$env:SystemRoot\Fonts\$f"))
            {
                Copy-Item "$DirDestino\$f" "$env:SystemRoot\Fonts\$f" 
            }

            #Arrancar com o e-DeiaLab
            Start-Process "$DirDestino\menulab.exe"

    }
    End
    {
    }
}