Export/Public/Receive-BusinessCentralDVD.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function Receive-BusinessCentralDVD {
    [CmdletBinding()]
    <#
    .SYNOPSIS
        Downloads a Business Central DVD
    .DESCRIPTION
        ...
    #>

    param(
        [Parameter(Mandatory = $false)]
        [string]
        $Version = "14",
        [Parameter(Mandatory = $false)]
        [string]
        $CumulativeUpdate = "CU01",
        [Parameter(Mandatory = $false)]
        [string]
        $Language = "W1",
        [Parameter(Mandatory = $false)]
        [string]
        $DownloadDirectory = "C:\Install\"
    )
    process {
        Add-Type -AssemblyName System.Web

        $UrlToDownload = Get-BusinessCentralDownloadURL -Version $Version -CumulativeUpdate $CumulativeUpdate -Language $Language
        if (-not($UrlToDownload)){
            Write-Error "Download URL not found."
            return
        }
        $filename = Split-Path $UrlToDownload -Leaf
        $dvdFilename = Join-Path $DownloadDirectory $filename

        if (!(Test-Path $DownloadDirectory)) {
            New-Item -ItemType Directory -Path  $DownloadDirectory | Out-Null
        }
        if (!(Test-Path $dvdFilename)) {
            Write-Verbose "Downloading File:"
            Write-Verbose " URL: $UrlToDownload"
            Write-Verbose " Filename: $dvdFilename"
            $clnt = New-Object System.Net.WebClient
            $clnt.DownloadFile($UrlToDownload, $dvdFilename)
            Write-Verbose "Download complete"
        }
        else { 
            Write-Verbose "File $dvdFilename already exists."
        }
        $dvdFilename        
    }
}
Export-ModuleMember Receive-BusinessCentralDVD