dev/Dev-BcSetup.ps1

#Requires -RunAsAdministrator

. "$($PSScriptRoot)\..\functions\setup\Get-BcDvdUrl.ps1"
. "$($PSScriptRoot)\..\functions\setup\Get-BcDvd.ps1"
. "$($PSScriptRoot)\..\functions\setup\Test-BcInstalled.ps1"
. "$($PSScriptRoot)\..\functions\setup\Install-Bc.ps1"
. "$($PSScriptRoot)\..\functions\setup\Uninstall-Bc.ps1"
. "$($PSScriptRoot)\..\functions\setup\Start-BcSetup.ps1"
. "$($PSScriptRoot)\..\functions\setup\Get-ManagementPathFromMsiLog.ps1"
. "$($PSScriptRoot)\..\functions\setup\Get-Uninstall.ps1"
. "$($PSScriptRoot)\..\functions\setup\Get-BcInstallationProperty.ps1"
. "$($PSScriptRoot)\..\functions\Import-BcManagement.ps1"

$MajorVersion = 23
$MinorVersion = 1
$CountryCode = 'DE'
# $DvdRepositoryPath = 'C:\DVD\BC'

Write-Host "Installing Microsoft Dynamics 365 Business Central $($CountryCode) (v$($MajorVersion).$($MinorVersion))"
# Write-Host "Using: $(Get-BcDvdUrl -MajorVersion $MajorVersion -MinorVersion $MinorVersion -CountryCode $CountryCode)"
# Write-Host "At: $(Get-BcDvD -MajorVersion $MajorVersion -MinorVersion $MinorVersion -CountryCode $CountryCode -DvdRepositoryPath $DvdRepositoryPath)"

# $IsServiceInstalled = Test-BcInstalled -MajorVersion $MajorVersion -Component Service
# $IsWebClientInstalled = Test-BcInstalled -MajorVersion $MajorVersion -Component WebClient
# Write-Host "Get-BcInstallationProperty (Service installed): $($IsServiceInstalled)"
# Write-Host "Get-BcInstallationProperty (Web Client installed): $($IsWebClientInstalled)"

# if ($IsWebClientInstalled)
# {
# Write-Host "Uninstall BC Web Client"
# Uninstall-Bc -MajorVersion $MajorVersion -Component WebClient
# }

# if ($IsServiceInstalled)
# {
# Write-Host "Uninstall BC Service"
# Uninstall-Bc -MajorVersion $MajorVersion -Component Service
# }

Write-Host "Install BC Service"
Start-BcSetup -MajorVersion $MajorVersion -MinorVersion $MinorVersion -CountryCode $CountryCode -AcceptTOS

Write-Host "Install BC Web Client"
Start-BcSetup -MajorVersion $MajorVersion -MinorVersion $MinorVersion -CountryCode $CountryCode -NoService -InstallWebClient -AcceptTOS

# Write-Host "Get-ManagementPathFromMsiLog:"
# Get-ManagementPathFromMsiLog -LogFilePath "C:\DVD\BC\23\1\DE\ServiceTier.SetupLog.txt"
# $BcManagementPath = Get-ManagementPathFromMsiLog -LogFilePath $LogPath
# Write-Host $BcManagementPath

Write-Host "Import BC PowerShell management tools"
Import-BcManagement -MajorVersion $MajorVersion

Get-NAVServerInstance | Where-Object { $_.Version -like "$($MajorVersion)*" } | Format-Table

# Write-Host "List installed Microsoft Dynamics components"
# Get-Uninstall | Where-Object { $_.DisplayName -like '*Microsoft Dynamics*' }