AppHandling/Repair-NavContainerApp.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<#
 .Synopsis
  Repairs App in a NAV/BC Container
 .Description
  Repairs a Business Central App by recompiling it against the current base application. Use this cmdlet if the base application has changed since publishing the Business Central App.
  It is recommended that the Business Central Server instance is restarted after running the repair.
 .Parameter containerName
  Name of the container in which you want to repair an app (default is navserver)
 .Parameter appName
  Name of app you want to repair in the container
 .Parameter appVersion
  Version of app you want to repair in the container
 .Example
  Repair-NavContainerApp -containerName test2 -appName myapp
#>

function Repair-NavContainerApp {
    Param(
        [string] $containerName = "navserver",
        [Parameter(Mandatory=$true)]
        [string] $appName,
        [Parameter()]
        [string] $appVersion
    )

    Invoke-ScriptInNavContainer -containerName $containerName -ScriptBlock { Param($appName, $appVersion)
        Write-Host "Repairing $appName"
        $parameters = @{
            "ServerInstance" = $ServerInstance;
            "Name" = $appName
        }
        if ($appVersion)
        {
            $parameters += @{ "Version" = $appVersion }
        }
        Repair-NavApp @parameters
    } -ArgumentList $appName, $appVersion
}
Set-Alias -Name Repair-BCContainerApp -Value Repair-NavContainerApp
Export-ModuleMember -Function Repair-NavContainerApp -Alias Repair-BCContainerApp