Public/New-P1ServerInstance.ps1

function New-P1ServerInstance {
    <#
    .Synopsis
    Install a new PlannerOne service.
 
    .Description
    Install a new PlannerOne service with the given parameters.
 
    .Parameter Tenant
    The tenant name of this service.
     
    .Parameter ERP
    The adapter to use (NAV, AP, SAGE)
 
    .Example
    # Install a PlannerOne service for the tenant Prod.
    New-P1ServerInstance -Tenant Prod -Login PlanAdm -Password MyPassword
    #>

    [cmdletbinding()]
    param( 
        [Parameter(Mandatory=$true)]
        [string] $Tenant,
        [Parameter(Mandatory=$true)]
        [string] $ERP
    )
    Process
    {
        Write-Section "Creating new server instance..."
        $serviceName = Get-ServiceNameFromTenant $Tenant
        $displayName = Get-ServiceDisplayNameFromTenant $Tenant
        $servicePath = Get-ServicePath
        
        $packageName = Get-PackageName $P1SrvPackage $ERP
        $srvBinPath = Get-PackageFolder($packageName)
        Write-Verbose "Server package folder is $srvBinPath"
        $srvBinFolder = "AppServer"

        #Test if service already exists
        if (Test-ServiceExists($serviceName)) {
            Write-Warning "Service $serviceName already exists!"
        } else {
            # Create folder for the service
            if (!(Test-Path $servicePath)) {
                mkdir $servicePath | Out-Null
            }
            
            # Link folder to repository
            $serverPath = Get-ServerPathFromTenant $Tenant
            New-Symlink $serverPath "$srvBinPath\$srvBinFolder"

            Write-Verbose "Creating new PlannerOne service for Tenant $Tenant"
            New-Service -Name $serviceName -BinaryPathName "$servicePath\$Tenant\$P1SrvExe" -displayName $displayName -startupType Automatic | Out-Null
            Start-Service -Name $serviceName
        }

        Write-OK "Server created"
    }
}