Private/Receive-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 if (!(Test-Path $folderpath)) { New-Item -ItemType Directory -Path $folderpath | Out-Null } if (!(Test-Path $dvdFilename)) { 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 $dvdPath = Join-Path $folderpath "DVD" if (-not (Test-Path (Join-Path $dvdPath 'setup.exe'))) { Write-Host "Unzipping $dvdFilename" Expand-Archive -Path $dvdFilename -DestinationPath $dvdPath Write-Host "Unzip complete" -ForegroundColor Green # Get DVD-Zip from just extracted dir $dvdZipfile = Get-ChildItem -Path $dvdPath -Filter *.zip | Select-Object -First 1 | % { $_.FullName } # Move extracted ZIP to parent and delete remaining directory Write-Host "Cleaning up directory..." Move-Item $dvdZipfile $folderpath Remove-Item $dvdPath -Confirm:$false -Force -Recurse # Find moved file and Unzip it $dvdZipfile = Get-ChildItem -Path $folderpath -Filter *.zip | Where-Object { $_.Name -ne $filename } | Select-Object -First 1 | % { $_.FullName } Write-Host "Unzipping $dvdZipfile" Expand-Archive -Path $dvdZipfile -DestinationPath $dvdPath Write-Host "Unzip complete" -ForegroundColor Green # Remove previously extracted ZIP (from other ZIP) $dvdZipfile = Get-ChildItem -Path $folderpath -Filter *.DVD.zip | Where-Object { $_.Name -ne $filename } | Select-Object -First 1 | % { $_.FullName } Remove-Item $dvdZipfile -Confirm:$false -Force -Recurse } } } |