AppHandling/UnPublish-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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<#
 .Synopsis
  Unpublish App in NAV/BC Container
 .Description
  Creates a session to the container and runs the CmdLet Unpublish-NavApp in the container
 .Parameter containerName
  Name of the container in which you want to unpublish the app (default navserver)
 .Parameter appName
  Name of app you want to unpublish in the container
 .Parameter uninstall
  Include this parameter if you want to uninstall the app before unpublishing
 .Parameter doNotSaveData
  Include this flag to indicate that you do not wish to save data when uninstalling the app
 .Parameter force
  Include this flag to indicate that you want to force uninstall the app
 .Parameter publisher
  Publisher of the app you want to unpublish
 .Parameter version
  Version of the app you want to unpublish
 .Parameter tenant
  If you specify the uninstall switch, then you can specify the tenant from which you want to uninstall the app
 .Example
  Unpublish-NavContainerApp -containerName test2 -appName myapp
 .Example
  Unpublish-NavContainerApp -containerName test2 -appName myapp -uninstall
#>

function UnPublish-NavContainerApp {
    Param (
        [string] $containerName = "navserver",
        [Parameter(Mandatory=$true)]
        [string] $appName,
        [switch] $unInstall,
        [switch] $doNotSaveData,
        [switch] $force,
        [Parameter(Mandatory=$false)]
        [string] $publisher,
        [Parameter(Mandatory=$false)]
        [string] $version,
        [Parameter(Mandatory=$false)]
        [string] $tenant = "default"
    )

    Invoke-ScriptInNavContainer -containerName $containerName -ScriptBlock { Param($appName, $unInstall, $tenant, $publisher, $version, $doNotSaveData, $force)
        if ($unInstall) {
            Write-Host "Uninstalling $appName from tenant $tenant"
            $params = @{}
            if ($doNotSaveData) {
                $params += @{ "DoNotSaveData" = $true }
            }
            if ($force) {
                $params += @{ "force" = $true }
            }
            Uninstall-NavApp -ServerInstance $ServerInstance -Name $appName -Tenant $tenant @params
        }
        $params = @{}
        if ($publisher) {
            $params += @{ 'Publisher' = $publisher }
        }
        if ($version) {
            $params += @{ 'Version' = $version }
        }
        Write-Host "Unpublishing $appName"
        Unpublish-NavApp -ServerInstance $ServerInstance -Name $appName @params
    } -ArgumentList $appName, $unInstall, $tenant, $publisher, $version, $doNotSaveData, $force
    Write-Host -ForegroundColor Green "App successfully unpublished"
}
Set-Alias -Name UnPublish-BCContainerApp -Value UnPublish-NavContainerApp
Export-ModuleMember -Function UnPublish-NavContainerApp -Alias UnPublish-BCContainerApp