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.
 
    .Example
    # Install a PlannerOne service for the tenant Prod.
    New-P1ServerInstance -Tenant Prod -Login PlanAdm -Password MyPassword
    #>

    [cmdletbinding()]
    param( 
        [Parameter(Mandatory=$true)]
        [string] $Tenant
    )
    Process
    {
        Write-Section "Creating new server instance..."
        $serviceName = Get-ServiceNameFromTenant $Tenant
        $displayName = Get-ServiceDisplayNameFromTenant $Tenant
        $servicePath = Get-ServicePath
        
        $srvBinPath = Get-PackageFolder($P1SrvPackage)
        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"
    }
}