Extension/Upgrade-Extensions.ps1

<#
.SYNOPSIS
    Upgrades extensions in the database
.EXAMPLE
    Upgrade-Extensions -instanceName n721
    Install patch from file
.NOTES
    Instances from destenation parameter must be configured to accept NTLM auth and have API endpoint enabled.
    Must be run as administrator because it requires to tun Sync-NavTenant cmdlet.
#>

function Upgrade-Extension {
    [cmdletbinding()]
    param(
        # Destination BC instance where extensions should be installed to.
        [Parameter(Mandatory = $True, ValueFromPipeline)]
        [string]$instanceName,
        # Path to extensions folder (.app files)
        [Parameter(Mandatory = $false)]
        [string]$path = (Get-Location),
        # Array of app file names
        [Parameter(Mandatory = $false)]
        [string[]]$apps
    )
    process {
        # Error handling behavior
        $ErrorActionPreference = "Stop"
        Write-Host "Upgrading extensions on $instanceName" -ForegroundColor Green
        $UpgradeScriptPath = Join-Path $PSScriptRoot "Extension Upgrade Scripts\ExtensionUpgrade.ps1"
        if (-not $apps) {
            $apps = Get-ChildItem -Path $path -Filter '*.app' -File | % { [System.IO.Path]::GetFileName($_) }
        }
        if (-not $apps) { throw "No apps found in $path" }
        $apps | % {
            Write-Host $_ -ForegroundColor Gray
            & $UpgradeScriptPath -ServerInstance $instanceName -Path (Join-Path $path $_) -SkipVerification $True -InstallIfAbsent $True | Write-Host
        }
    }
}