functions/setup/Install-Bc.ps1

function Install-Bc
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [string]$DvdPath,
        [Parameter(Mandatory=$true)]
        [ValidateSet('Service', 'WebClient')]
        [string]$Component,
        [switch]$AcceptTOS
    )

    if (-not $AcceptTOS)
    {
        throw 'You have to accept the terms of service to continue. Read this: https://learn.microsoft.com/de-de/dynamics365/business-central/dev-itpro/terms/legal-onpremises. If you agree you have to accept by using parameter -AcceptTOS.'
    }

    switch ($Component) {
        'Service'
            {
                $MsiPath = "$($DvdPath)\ServiceTier\Microsoft Dynamics 365 Business Central Server.msi"
                $LogPath = "$($DvdPath)\ServiceTier.SetupLog.txt"
            }
        'WebClient'
            {
                $MsiPath = "$($DvdPath)\WebClient\Microsoft Dynamics 365 Business Central Web Client.msi"
                $LogPath = "$($DvdPath)\WebClient.SetupLog.txt"
            }
    }

    if (Test-Path -Path $MsiPath -PathType Leaf)
    {
        $MsiArgumentList = " /quiet /log `"$LogPath`" /i `"$MsiPath`" SERVERINSTANCE=BC230 MANAGEMENTAPISERVICESPORT=7044 MANAGEMENTSERVICEPORT=7045 SERVICEPORT=7046 WEBSERVICEPORT=7047 DATASERVICEPORT=7048 DEVELOPERSERVICESPORT=7049 SNAPSHOTDEBUGGERSERVICESPORT=7050 WEBSERVICEENABLED=false DATASERVICEENABLED=false DEVELOPERSERVICESENABLED=false SNAPSHOTDEBUGGERENABLED=no"
        $ReturnCode = Start-Process msiexec.exe -ArgumentList $MsiArgumentList -Wait
        Write-Output $ReturnCode
    } 
    else
    {
        Write-Error "MSI not found: $($MsiPath)"
    }
}