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
    {    
        If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
        [Security.Principal.WindowsBuiltInRole] "Administrator")) 
        { 
            Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!" 
            Break 
        } 
        $Caption = (Get-WmiObject "win32_operatingsystem" | Select caption).Caption 
        If(-not ($Caption -match "Microsoft Windows 8" -OR $Caption -match "Microsoft Windows 7" -OR $Caption -match "Microsoft Windows 10") )
            { 
                Write-Error "Please run this script in Windows 10, Windows 8/8.1 or Windows 7" 
            }
    }
    Process
    {
    
            #Preciso verificar a ins
            #$DirDestino="c:\edeiax"
            #$Servidor="192.168.111.3"
            $Caption = (Get-WmiObject "win32_operatingsystem" | Select caption).Caption 
        
            If($Caption -match "Microsoft Windows 8" -OR $Caption -match "Microsoft Windows 7" -OR $Caption -match "Microsoft Windows 10") 
            { 
                $Result = Dism /online /get-featureinfo /featurename:NetFx3 
                If($Result -contains "State : Enabled") 
                { 
                    Write-Warning ".Net Framework 3.5 has been installed and enabled." 
                } 
                Else  
                { 
                        Write-Host "Installing .Net Framework 3.5, do not close this prompt..." |  
                        Dism /online /Enable-feature /featurename:NetFx3 | Out-Null  
                        $Result = Dism /online /Get-featureinfo /featurename:NetFx3 
                        If($Result -contains "State : Enabled") 
                        { 
                            Write-Host "Install .Net Framework 3.5 successfully." 
                        } 
                        Else 
                        { 
                            Write-Host "Failed to install Install .Net Framework 3.5, you can use local source to try again." 
                        }         
                        #DISM.exe /online /enable-feature /all /featurename:NetFx4
                } 
                             
                #.net 4.0
                $Result = Dism /online /get-featureinfo /featurename:NetFx4 
                If($Result -contains "State : Enabled") 
                { 
                    Write-Warning ".Net Framework 4 has been installed and enabled." 
                } 
                Else  
                { 
                        Write-Host "Installing .Net Framework 4, do not close this prompt..." |  
                        Dism /online /Enable-feature /featurename:NetFx4 | Out-Null  
                        $Result = Dism /online /Get-featureinfo /featurename:NetFx4 
                        If($Result -contains "State : Enabled") 
                        { 
                            Write-Host "Install .Net Framework 4 successfully." 
                        } 
                        Else 
                        { 
                            Write-Host "Failed to install Install .Net Framework 4, you can use local source to try again." 
                        }         
                        #DISM.exe /online /enable-feature /all /featurename:NetFx4
                } 
 
            } 
            Else 
            { 
                Write-Error "Please run this script in Windows 10, Windows 8/8.1 or Windows 7" 
            } 


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

            if (-not(Test-Path -Path $DirDestino))
            {
                Write-Verbose "Criar diretório $DirDestino"
                New-Item -Path $DirDestino -ItemType Directory
            }

            # descarregar o necessário do servidor cliente ou remoto

            $filelocal="menulab.exe"
            Write-Verbose "Download file http://$servidor/edeia/$filelocal para $DirDestino\$filelocal"
            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)
            {
                Write-Verbose "Download file http://segilac.no-ip.org/edeia/tools/InstalacaoLocal/$f para $DirDestino\$f"
                Start-BitsTransfer -Source "http://segilac.no-ip.org/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)
            {
                Write-Verbose "Editar menulab.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"))
            {
                Write-Verbose "Download .net framework 4"
                Start-BitsTransfer -Source "http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/$f" -Destination "$DirDestino\$f"
            }
            Write-Verbose "Instalar .net framework 4"
            Start-Process -FilePath "$DirDestino\$f" -ArgumentList "/q /norestart" -wait
            #>


            $f=""

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

                $fileremoto="CRRedist2008_x64.msi", "CRRuntime_64bit_13_0_8.msi"
                foreach ($f in $fileremoto)
                {   
                    if (-not (Test-Path -Path  "$DirDestino\$f"))
                    {
                        Write-Verbose "Download http://segilac.no-ip.org/edeia/tools/InstalacaoLocal/$f para $DirDestino\$f"
                        Start-BitsTransfer -Source "http://segilac.no-ip.org/edeia/tools/InstalacaoLocal/$f" -Destination "$DirDestino\$f"           
                    }
                    #Write-Output "http://192.168.111.1/edeia/tools/InstalacaoLocal/$f"
                    # deploy Crystal Reports
                    Write-Verbose "Instalar $DirDestino\$f"
                    Start-Process "$DirDestino\$f" /qn -Wait -Verbose
                }
            }
            else
            {
                 #instalar 32 bits
                $fileremoto="CRRedist2008_x86.msi", "CRRuntime_32bit_13_0_8.msi"
                foreach ($f in $fileremoto)
                {  
                    if (-not (Test-Path -Path  "$DirDestino\$f"))
                        {  
                             Write-Verbose "Download http://segilac.no-ip.org/edeia/tools/InstalacaoLocal/$f para $DirDestino\$f"
                            Start-BitsTransfer -Source "http://segilac.no-ip.org/edeia/tools/InstalacaoLocal/$f" -Destination "$DirDestino\$f" 
                
                        }
                    # deploy Crystal Reports
                    Write-Verbose "Instalar $DirDestino\$f"
                    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"
            
            if(-not (Test-Path -Path "$env:windir\fonts\$f"))
            {
                Write-Verbose "Download Font e instalar $DirDestino\$f"
                Start-BitsTransfer -Source "http://segilac.no-ip.org/edeia/tools/InstalacaoLocal/$f" -Destination "$DirDestino\$f" 

                $FONTS = 0x14
                $objShell = New-Object -ComObject Shell.Application
                $objFolder = $objShell.Namespace($FONTS)
                $objFolder.CopyHere("$DirDestino\$f")
            }
            #$objFolder.CopyHere("$DirDestino\$f")


            #Arrancar com o e-DeiaLab
            Start-Process "$DirDestino\menulab.exe"
            Write-Verbose "Instalação terminada"
    }
    End
    {
    }
}