Private/Install-BusinessCentral.ps1
# Will be called in VM function Global:Install-BusinessCentral { [CmdletBinding()] <# .SYNOPSIS ... .DESCRIPTION ... #> param( [Parameter(Mandatory = $false, Position = 1)] [string] $DownloadDirectory = "C:\Install\DVD", [Parameter(Mandatory = $false, Position = 2)] [string] $ConfigurationFile, [Parameter(Mandatory = $false, Position = 4)] [string] $LicenseFilename, [ValidateSet('App', 'Web')] [Parameter(Mandatory = $false, Position = 5)] [string] $InstallationType = "App", [Parameter(Mandatory = $false, Position = 6)] [ValidateSet('13', '14', '15')] [string] $Version ) # Check prerequisities if (-not (Get-Module -Name Cloud.Ready.Software.NAV)) { Write-CustomHost -Message "Importing Module Cloud.Ready.Software.NAV" Import-Module Cloud.Ready.Software.NAV -Force -Verbose:$false -DisableNameChecking -WarningAction SilentlyContinue } $setupFilename = Join-Path $DownloadDirectory 'setup.exe' if (-not(Test-Path $setupFilename)) { throw "$setupFilename doesn not exist. Make sure that 'DownloadDirectory' contains the path to the extracted DVD." } # Create Default Configuration if file was not given if ([string]::IsNullOrEmpty($ConfigurationFile)) { $configArgs = @{ } if (-not([string]::IsNullOrEmpty($InstallationType))) { $configArgs.Add('InstallationType', $InstallationType) } if (-not([string]::IsNullOrEmpty($Version))) { $configArgs.Add('BusinessCentralVersion', $Version) } if (-not([string]::IsNullOrEmpty($DownloadDirectory))) { $FileDirectory = Split-Path $DownloadDirectory -Parent $configArgs.Add('FileDirectory', $FileDirectory) } $ConfigurationFile = Get-BusinessCentralDefaultInstallConfig @configArgs } # Check if it's necessary to download the config-file if (-not(Test-Path $ConfigurationFile)) { $DestinationFilename = Join-Path (Split-Path $DownloadDirectory -Parent) (Split-Path $ConfigurationFile -Leaf) Download-CustomFile -URI $ConfigurationFile -DestinationFile $DestinationFilename $ConfigurationFile = $DestinationFilename } # Start Install $LogPath = Join-Path (Split-Path $DownloadDirectory -Parent) '\Log\NavInstallLog.txt' $scriptblock = { param($DownloadDirectory, $ConfigurationFile, $LicenseFilename, $LogPath) Install-NAV -DVDFolder $DownloadDirectory -Configfile $ConfigurationFile -LicenseFile $LicenseFilename -Log $LogPath } Invoke-CommandAs -ScriptBlock $scriptblock -AsSystem -ArgumentList $DownloadDirectory, $ConfigurationFile, $LogPath #Install-NAV -DVDFolder $DownloadDirectory -Configfile $ConfigurationFile -LicenseFile $LicenseFilename -Log $LogPath } |