Public/Set-P1Adapter.ps1

function Set-P1Adapter {
    <#
    .Synopsis
    Configuration of the Microsoft Dynamics NAV Adapter.
 
    .Description
    Configure the Microsoft Dynamics NAV Adapter for PlannerOne.
 
    .Parameter Tenant
    The tenant name.
 
    .Parameter ERP
    The ERP name (NAV, SAGE...)
 
    .Parameter Server
    The tenant Microsoft Dynamics NAV host server name.
     
    .Parameter SOAPPort
    The NAV Web service SOAP port.
     
    .Parameter AuthenticationMode
    The NAV authentication mode (Negotiate, NTLM, Digest, Basic).
     
    .Parameter SSL
    Does the NAV server use SSL.
     
    .Parameter ClientPort
    The port for Microst Dynamics NAV RTC client.
     
    .Parameter InstanceName
    The NAV server instance name.
     
    .Parameter ServiceDomain
    The PlannerOne technical account domain.
                     
    .Parameter ServiceLogin
    The PlannerOne technical account login.
                     
    .Parameter ServicePassword
    The PlannerOne technical account password.
     
    .Parameter AutoPort
    Read ports from Microsoft Dynamics NAV instance configuration provided with InstanceName
     
    .Parameter NAVVersion
    The NAVVersion to use for Powershell module tools (60, 70, 80, 90...)
                                                             
    .Example
    # Configure a NAV adapter
    Set-P1NavConfiguration -Tenant nodb -ServiceDomain ORTEMS -ServiceLogin PlannerOne -ServicePassword Planner1 -Server locahost -InstanceName DynamicsNAV90 -SOAPPort 9047
    #>

    [cmdletbinding()]
    param( 
    [Parameter(Mandatory=$true)]
        [string] $Tenant,
        [Parameter(Mandatory=$true)]
    [string] $ERP,
        [string] $Server,
        [int] $SOAPPort,
        [string] $AuthenticationMode,
        [bool] $SSL,
        [int] $ClientPort,
    [Parameter(Mandatory=$true)]
        [string] $InstanceName,
        [string] $ServiceDomain,
    [Parameter(Mandatory=$true)]
        [string] $ServiceLogin,
    [Parameter(Mandatory=$true)]
        [string] $ServicePassword,
        [switch] $AutoPort,
        [string] $NAVVersion
    )
    Process
    {
        if (!(Test-Tenant $Tenant)) {
                Write-Warning "Tenant $Tenant does not exist."
                return
        }
        
    if ($ERP -eq "NAV") {
        Write-Section "Configuring NAV Adapter..."
                
                if ($InstanceName -eq "") {
                        Write-Warning "Microsoft Dynamics NAV Instance name is missing."
                        return        
                }       
                        
                $NAVConfig = Get-NAVParametersFromConfig -InstanceName $InstanceName -NAVVersion $NAVVersion 
                if ($AutoPort) {                        
                        if ($NAVConfig -eq $null) {
                                Write-Warning "No NAV configuration. PlannerOne Configuration canceled."
                                return
                        }
                        
                        $InstanceName = $NAVConfig.InstanceName
                        $SOAPPort = $NAVConfig.SOAPPort
                        $ClientPort = $NAVConfig.ClientPort
                }
                
                if ($NAVConfig -ne $null) {
                        if ($NAVConfig.SOAPPort -ne $SOAPPort) {
                                $port = $NAVConfig.SOAPPort
                                Write-Warning "SOAP Port $SOAPPort is not the one set for Microsoft Dynamics NAV instance $InstanceName`: $port"
                                Write-Warning "You can use -AutoPort switch to automatically use the ports configured in Microsoft Dynamics NAV."
                                Write-Warning "PlannerOne adapter configuration canceled."
                                return;
                        }
                        
                        if ($NAVConfig.SOAPServicesEnabled -ne "true") {
                                Write-Warning "SOAP service is not enabled in Microsoft Dynamics NAV instance $InstanceName"
                                Write-Warning "PlannerOne adapter configuration canceled."
                                return;
                        }
                        
                        if ($NAVConfig.ServicesDefaultTimeZone -ne "Server Time Zone") {
                                $timezone = $NAVConfig.ServicesDefaultTimeZone
                                Write-Warning "SOAP service time zone should be 'Server Time Zone'. Current value in Microsoft Dynamics NAV instance $InstanceName`: $timezone"
                                Write-Warning "PlannerOne adapter configuration canceled."
                                return;
                        }                        
                } else {
                        Write-Warning "Cannot read Microsoft Dynamics NAV configuration: parameters won't be validated. Run with -verbose for more technical informations."
                }
                
            Set-NAVParameters $Tenant $Server $SOAPPort $AuthenticationMode $SSL $ClientPort $InstanceName $ServiceDomain $ServiceLogin $ServicePassword
        
            $serviceName = Get-ServiceNameFromTenant $Tenant
        
            Write-Output "Restarting PlannerOne service $serviceName..."
            Restart-Service -Name $serviceName
        Write-OK "Configuration done"
    } else {
        Write-Warning "ERP $ERP not recognized"
    }
    }
}