Additions/Upgrade-AdditionsInDatabase.ps1

function Upgrade-AdditionsInDatabase
{
    Param(
        [Parameter(Mandatory=$true)]
        [string]$DatabaseServer,
        [Parameter(Mandatory=$true)]
        [string]$DatabaseName,
        [Parameter(Mandatory=$false)]
        [string[]]$AdditionsBranches,
        [Parameter(Mandatory=$false)]
        [string]$NavServer,
        [Parameter(Mandatory=$false)]
        [string]$ServerInstance

    )

    Write-Host -ForegroundColor Green 'Exporting application objects'
    $ObjectFile = '{0}\{1}.TXT' -f $env:TEMP, ([Guid]::NewGuid().ToString())
    Export-NAVApplicationObject -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName -Path $ObjectFile
    $TargetPath = Create-TempDirectory
    Split-NAVApplicationObjectFile -Source $ObjectFile -Destination $TargetPath

    Write-Host -ForegroundColor Green 'Applying additions'
    $ResultPath = Upgrade-AdditionsInFolder -TargetPath $TargetPath -AdditionsBranches $AdditionsBranches
    $ResultFile = '{0}\{1}.TXT' -f $env:TEMP, ([Guid]::NewGuid().ToString())
    Join-NAVApplicationObjectFile -Source $ResultPath -Destination $ResultFile

    Write-Host -ForegroundColor Green 'Importing and compiling objects'
    if (Test-Path $ResultFile)
    {
        Import-NAVApplicationObject -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName -Path $ResultFile -SynchronizeSchemaChanges No -Confirm:$false
        Compile-NAVApplicationObject -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName -SynchronizeSchemaChanges No -NavServerName $NavServer -NavServerInstance $ServerInstance        
    }

    Remove-Item $ObjectFile -Force
    Remove-Item $TargetPath -Recurse -Force
    Remove-Item $ResultPath -Recurse -Force
    Remove-Item $ResultFile -Force
}

Export-ModuleMember -Function Upgrade-AdditionsInDatabase