Private/Download-BusinessCentralDVD.ps1

# Will be called in VM
function Global:Receive-BusinessCentralDVD {
    [CmdletBinding()]
    <#
    .SYNOPSIS
        Initializes the newly created VM
    .DESCRIPTION
        ...
    #>

    param(
        [Parameter(Mandatory = $false, Position = 3)]
        [string]
        $Version,
        [Parameter(Mandatory = $false, Position = 4)]
        [string]
        $CumulativeUpdate,
        [Parameter(Mandatory = $false, Position = 5)]
        [string]
        $Language
    )
    process {
        $folderpath = "C:\Install\"
        $filename = "BC DVD.zip"
        $dvdFilename = Join-Path $folderpath $filename

        $UrlToDownload = Get-BusinessCentralDownloadUrl -Version $Version -CumulativeUpdate $CumulativeUpdate -Language $Language

        $parent = Split-Path -Path $destinationPath -Parent
        if (!(Test-Path $parent)) {
            New-Item -ItemType Directory -Path  $parent | Out-Null
        }
        if (!(Test-Path $destinationPath)) {
            write-host "Downloading NAV/BC DVD..."
            $clnt = New-Object System.Net.WebClient
            $clnt.DownloadFile($UrlToDownload, $dvdFilename)
            Write-Host "Download complete" -ForegroundColor Green 
        }
        else { 
            Write-Host "File already exists."
        }

        # Unzip downloaded file
        Write-Host "Unzipping $dvdFilename"
        $dvdPath = Join-Path $folderpath "DVD"
        Expand-Archive -Path $dvdFilename -DestinationPath $dvdPath
        Write-Host "Unzip complete" -ForegroundColor Green 
    }
}

Get-Verb