HelperFunctions/Install-Prerequisite.ps1

<#
 .Synopsis
  Installs prerequisite for Business Central
 .Description
  Downloads and Installs prerequisites for Business Central
 .Parameter Name
  Name of the prerequisite
 .Parameter MsiPath
  Path where the prerequisites installer should be
 .Parameter MsiUrl
  Url to the installer, if not locally existing yet
 .Example
  Install-Prerequisite -Name "Url Rewrite" -MsiPath "C:\Install\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"
#>

function Install-Prerequisite {
    Param(
        [Parameter(Mandatory=$true)]
        [string]$Name,
        [Parameter(Mandatory=$true)]
        [string]$MsiPath,
        [Parameter(Mandatory=$true)]
        [string]$MsiUrl
    )

    if (!(Test-Path $MsiPath)) {
        Write-Output "Downloading $Name"
        $MsiFolder = [System.IO.Path]::GetDirectoryName($MsiPath)
        if (!(Test-Path $MsiFolder)) {
            New-Item -Path $MsiFolder -ItemType Directory | Out-Null
        }
        [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
        (New-Object System.Net.WebClient).DownloadFile($MsiUrl, $MsiPath)
    }
    Write-Output "Installing $Name"
    start-process $MsiPath -ArgumentList "/quiet /qn /passive" -Wait
} Export-ModuleMember Install-Prerequisite