BCInstall/Install-BCVersion.ps1

<#
 .Synopsis
  Installs Business Central
 .Description
  Installs Business Central based on the path that is provided
 .Parameter installPath
  Path with the installation files
 .Example
  Get-BCFile -installPath 'C:\install\'
  Install-BCVersion -installPath 'C:\install'
#>

function Install-BCVersion {
    Param(
        [Parameter(Mandatory = $true)]
        [String]
        $installPath
    )

    if (!(Test-Path $installPath -PathType Container)) {
        Write-Error "Install folder not found"
    }
    if (!(Test-Path "C:\Installs" -PathType Container)) {
        New-Item "C:\Installs" -ItemType Directory | Out-Null
    }

    # Installing Prerequisites
    Install-IiServer

    Install-Prerequisite -Name "Url Rewrite" -MsiPath "$InstallPath\Prerequisite Components\IIS URL Rewrite Module\rewrite_2.0.rtw_x64.msi" -MsiUrl "https://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi"
    Install-Prerequisite -Name "OpenXML" -MsiPath "$InstallPath\Prerequisite Components\Open XML SDK 2.5 for Microsoft Office\OpenXMLSDKv25.msi" -MsiUrl "https://download.microsoft.com/download/5/5/3/553C731E-9333-40FB-ADE3-E02DC9643B31/OpenXMLSDKV25.msi"

    if (Test-Path "$InstallPath\Prerequisite Components\DotNetCore") {
        $dotnetCoreExe = (Get-ChildItem -Path "$InstallPath\Prerequisite Components\DotNetCore" -Filter "*.exe").FullName
    } else {
        Write-Output "Downloading DotNetCore"
        $dotnetCoreDownloadUrl = "https://go.microsoft.com/fwlink/?LinkID=844461"
        $dotnetCoreExe = "$installPath\Prerequisite Components\DotNetCore\DotNetCore.1.0.4_1.1.1-WindowsHosting.exe"
        $dotnetCoreFolder = [System.IO.Path]::GetDirectoryName($dotnetCoreExe)
        if (!(Test-Path $dotnetCoreFolder)) {
            New-Item -Path $dotnetCoreFolder -ItemType Directory | Out-Null
        }
        [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
        (New-Object System.Net.WebClient).DownloadFile($dotnetCoreDownloadUrl, $dotnetCoreExe)
    }
    Write-Output "Installing DotNetCore"
    start-process $dotnetCoreExe -ArgumentList "/quiet" -Wait

    # start IIS Services
    Write-Output "Starting Internet Information Server"
    Start-Service -Name "W3SVC"

    # Installing BC
    Write-Output "Installing Server Components"
    Start-Process -FilePath "$InstallPath\ServiceTier\Microsoft Dynamics 365 Business Central Server.msi" -WorkingDirectory "$InstallPath\ServiceTier\" -ArgumentList "/qn /norestart" -Wait

    Write-Output "Installing Web Client Components"
    Start-Process -FilePath "$InstallPath\WebClient\Microsoft Dynamics 365 Business Central Web Client.msi" -WorkingDirectory "$InstallPath\WebClient\" -ArgumentList "/qn /norestart" -Wait

    Write-Output "Copying ModernDev Files"
    if (Test-Path "$InstallPath\ModernDev\program files\Microsoft Dynamics NAV") {
        Get-ChildItem -Path "$InstallPath\ModernDev\program files\Microsoft Dynamics NAV\" | Copy-Item -Destination "C:\Program Files\Microsoft Dynamics 365 Business Central\" -Recurse -Force
    }

    "ConfigurationPackages","Test Assemblies","TestToolKit","UpgradeToolKit","Extensions","Applications","Applications.*" | ForEach-Object {
        $dir = "$InstallPath\$_"
        if (Test-Path $dir -PathType Container)
        {
            Write-Output "Copying $_"
            Copy-Item -Path $dir -Destination "C:\Installs" -Recurse -Force
        }
    }

    # run local installers if present
    if (Test-Path "$InstallPath\Installers" -PathType Container) {
        Get-ChildItem "$InstallPath\Installers" -Recurse | Where-Object { $_.PSIsContainer } | ForEach-Object {
            Get-ChildItem $_.FullName | Where-Object { $_.PSIsContainer } | ForEach-Object {
                $dir = $_.FullName
                Get-ChildItem (Join-Path $dir "*.msi") | ForEach-Object {
                    $filepath = $_.FullName
                    if ($filepath.Contains('\WebHelp\')) {
                        Write-Output "Skipping $filepath"
                    } else {
                        Write-Output "Installing $filepath"
                        Start-Process -FilePath $filepath -WorkingDirectory $dir -ArgumentList "/qn /norestart" -Wait
                    }
                }
            }
        }
    }

    # Stop Standard Server created
    $standardServer = Get-NAVServerInstance | Where-Object {$_.ServerInstance -like 'MicrosoftDynamicsNavServer$BC*'}
    if ($null -ne $standardServer) {
        if ($standardServer.State -ne "stopped") {
            Stop-Service -Name $standardServer.ServerInstance -StartupType Manual
        }
        Set-Service $standardServer -StartupType
    }

}
Export-ModuleMember Install-BCVersion