CompanyHandling/Remove-CompanyInNavContainer.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
<#
 .Synopsis
  Remove a company from the NAV/BC Container
 .Description
  Create a session to a container and run Remove-NavCompany
 .Parameter containerName
  Name of the container from which you want to remove the company
  .Parameter tenant
  Name of tenant you want to remove the commpany from in the container
 .Parameter companyName
  Name of the company you want to remove
 .Example
  Remove-CompanyInNavContainer -containerName test2 -companyName 'My Company' -tenant mytenant
#>

function Remove-CompanyInNavContainer {
    Param(
        [string] $containerName = "navserver",
        [string] $tenant = "default",
        [Parameter(Mandatory=$true)]
        [string] $companyName
    )

    Invoke-ScriptInNavContainer -containerName $containerName -ScriptBlock { Param($companyName, $tenant)
        Write-Host "Removing company $companyName from $tenant"
        Remove-NavCompany -ServerInstance $ServerInstance -Tenant $tenant -CompanyName $companyName -ForceImmediateDataDeletion -Force
    } -ArgumentList $companyName, $tenant
    Write-Host -ForegroundColor Green "Company successfully removed"
}
Set-Alias -Name Remove-CompanyInBCContainer -Value Remove-CompanyInNavContainer
Export-ModuleMember -Function Remove-CompanyInNavContainer -Alias Remove-CompanyInBCContainer